/** * Converts the serialized form to an instance of {@link Credentials}. The original serialized * form will not be affected. * * @param serializedForm * serialized form of credentials * @return deserialized credentials */ public static final Credentials deserialize(String serializedForm) { String[] split = serializedForm.split(":", 3); String principal = split[0].equals("-") ? null : new String(Base64.getDecoder().decode(split[0]), UTF_8); String tokenType = split[1].equals("-") ? null : new String(Base64.getDecoder().decode(split[1]), UTF_8); AuthenticationToken token = null; if (!split[2].equals("-")) { byte[] tokenBytes = Base64.getDecoder().decode(split[2]); token = AuthenticationTokenSerializer.deserialize(tokenType, tokenBytes); } return new Credentials(principal, token); }
public static AuthenticationToken decodeToken(String className, String tokenString) { return AuthenticationToken.AuthenticationTokenSerializer.deserialize(className, Base64.getDecoder().decode(tokenString)); }
/** * An alternate version of {@link #deserialize(Class, byte[])} that accepts a token class name * rather than a token class. * * @param tokenClassName * the fully-qualified class name to be returned * @see #serialize(AuthenticationToken) */ public static AuthenticationToken deserialize(String tokenClassName, byte[] tokenBytes) { Class<? extends AuthenticationToken> tokenType = null; try { // @formatter:off @SuppressWarnings("unchecked") Class<? extends AuthenticationToken> tmpTokenType = (Class<? extends AuthenticationToken>) Class.forName(tokenClassName); // @formatter:on tokenType = tmpTokenType; } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Class not available " + tokenClassName, e); } return deserialize(tokenType, tokenBytes); }
byte[] tokenBytes = Base64.decodeBase64(base64TokenBytes); this.token = AuthenticationTokenSerializer.deserialize(tokenClass, tokenBytes); break;
String[] args = token.substring(TokenSource.INLINE.prefix().length()).split(":", 2); if (args.length == 2) return AuthenticationTokenSerializer.deserialize(args[0], Base64.decodeBase64(args[1].getBytes(UTF_8))); } else if (token.startsWith(TokenSource.FILE.prefix())) {
/** * An alternate version of {@link #deserialize(Class, byte[])} that accepts a token class name * rather than a token class. * * @param tokenClassName * the fully-qualified class name to be returned * @see #serialize(AuthenticationToken) */ public static AuthenticationToken deserialize(String tokenClassName, byte[] tokenBytes) { Class<? extends AuthenticationToken> tokenType = null; try { // @formatter:off @SuppressWarnings("unchecked") Class<? extends AuthenticationToken> tmpTokenType = (Class<? extends AuthenticationToken>) Class.forName(tokenClassName); // @formatter:on tokenType = tmpTokenType; } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Class not available " + tokenClassName, e); } return deserialize(tokenType, tokenBytes); }
/** * Converts the serialized form to an instance of {@link Credentials}. The original serialized * form will not be affected. * * @param serializedForm * serialized form of credentials * @return deserialized credentials */ public static final Credentials deserialize(String serializedForm) { String[] split = serializedForm.split(":", 3); String principal = split[0].equals("-") ? null : new String(Base64.decodeBase64(split[0]), UTF_8); String tokenType = split[1].equals("-") ? null : new String(Base64.decodeBase64(split[1]), UTF_8); AuthenticationToken token = null; if (!split[2].equals("-")) { byte[] tokenBytes = Base64.decodeBase64(split[2]); token = AuthenticationTokenSerializer.deserialize(tokenType, tokenBytes); } return new Credentials(principal, token); }
/** * Converts a given thrift object to our internal Credentials representation. * * @param serialized * a Thrift encoded set of credentials * @return a new Credentials instance; destroy the token when you're done. */ public static Credentials fromThrift(TCredentials serialized) { return new Credentials(serialized.getPrincipal(), AuthenticationTokenSerializer .deserialize(serialized.getTokenClassName(), serialized.getToken())); }
byte[] tokenBytes = Base64.getDecoder().decode(base64TokenBytes); this.token = AuthenticationTokenSerializer.deserialize(tokenClass, tokenBytes); break;
String[] args = token.substring(TokenSource.INLINE.prefix().length()).split(":", 2); if (args.length == 2) return AuthenticationTokenSerializer.deserialize(args[0], Base64.getDecoder().decode(args[1])); } else if (token.startsWith(TokenSource.FILE.prefix())) {
/** * Converts a given thrift object to our internal Credentials representation. * * @param serialized * a Thrift encoded set of credentials * @return a new Credentials instance; destroy the token when you're done. */ public static Credentials fromThrift(TCredentials serialized) { return new Credentials(serialized.getPrincipal(), AuthenticationTokenSerializer .deserialize(serialized.getTokenClassName(), serialized.getToken())); }