|
1 | 1 | /*
|
2 |
| - * Copyright 2019 the original author or authors. |
| 2 | + * Copyright 2019-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -71,18 +71,24 @@ private Authentication authentication(Map<String, Object> metadata) {
|
71 | 71 | if (authenticationMetadata == null) {
|
72 | 72 | return null;
|
73 | 73 | }
|
74 |
| - ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata); |
75 |
| - if (!AuthMetadataCodec.isWellKnownAuthType(rawAuthentication)) { |
76 |
| - return null; |
77 |
| - } |
78 |
| - WellKnownAuthType wellKnownAuthType = AuthMetadataCodec.readWellKnownAuthType(rawAuthentication); |
79 |
| - if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) { |
80 |
| - return simple(rawAuthentication); |
| 74 | + ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer(); |
| 75 | + try { |
| 76 | + rawAuthentication.writeBytes(authenticationMetadata); |
| 77 | + if (!AuthMetadataCodec.isWellKnownAuthType(rawAuthentication)) { |
| 78 | + return null; |
| 79 | + } |
| 80 | + WellKnownAuthType wellKnownAuthType = AuthMetadataCodec.readWellKnownAuthType(rawAuthentication); |
| 81 | + if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) { |
| 82 | + return simple(rawAuthentication); |
| 83 | + } |
| 84 | + if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) { |
| 85 | + return bearer(rawAuthentication); |
| 86 | + } |
| 87 | + throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType); |
81 | 88 | }
|
82 |
| - if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) { |
83 |
| - return bearer(rawAuthentication); |
| 89 | + finally { |
| 90 | + rawAuthentication.release(); |
84 | 91 | }
|
85 |
| - throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType); |
86 | 92 | }
|
87 | 93 |
|
88 | 94 | private Authentication simple(ByteBuf rawAuthentication) {
|
|
0 commit comments