|
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.
|
@@ -67,17 +67,23 @@ private Authentication authentication(Map<String, Object> metadata) {
|
67 | 67 | if (authenticationMetadata == null) {
|
68 | 68 | return null;
|
69 | 69 | }
|
70 |
| - ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer().writeBytes(authenticationMetadata); |
71 |
| - if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) { |
72 |
| - return null; |
| 70 | + ByteBuf rawAuthentication = ByteBufAllocator.DEFAULT.buffer(); |
| 71 | + try { |
| 72 | + rawAuthentication.writeBytes(authenticationMetadata); |
| 73 | + if (!AuthMetadataFlyweight.isWellKnownAuthType(rawAuthentication)) { |
| 74 | + return null; |
| 75 | + } |
| 76 | + WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication); |
| 77 | + if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) { |
| 78 | + return simple(rawAuthentication); |
| 79 | + } else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) { |
| 80 | + return bearer(rawAuthentication); |
| 81 | + } |
| 82 | + throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType); |
73 | 83 | }
|
74 |
| - WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(rawAuthentication); |
75 |
| - if (WellKnownAuthType.SIMPLE.equals(wellKnownAuthType)) { |
76 |
| - return simple(rawAuthentication); |
77 |
| - } else if (WellKnownAuthType.BEARER.equals(wellKnownAuthType)) { |
78 |
| - return bearer(rawAuthentication); |
| 84 | + finally { |
| 85 | + rawAuthentication.release(); |
79 | 86 | }
|
80 |
| - throw new IllegalArgumentException("Unknown Mime Type " + wellKnownAuthType); |
81 | 87 | }
|
82 | 88 |
|
83 | 89 | private Authentication simple(ByteBuf rawAuthentication) {
|
|
0 commit comments