/** * Construct with prepared authToken and token format. * * @param authToken The authToken * @param format The token format */ public KrbToken(AuthToken authToken, TokenFormat format) { this(); this.innerToken = authToken; setTokenType(); setTokenFormat(format); try { setTokenValue(getTokenEncoder(format).encodeAsBytes(innerToken)); } catch (KrbException e) { throw new RuntimeException("Failed to encode AuthToken", e); } }
/** * {@inheritDoc} */ /* @Override public void decode(ByteBuffer content) throws IOException { super.decode(content); this.innerToken = getTokenDecoder().decodeFromBytes(getTokenValue()); setTokenType(); }*/ @Override public void decode(Asn1ParseResult parseResult) throws IOException { super.decode(parseResult); if (getTokenValue() != null) { this.innerToken = getTokenDecoder(getTokenFormat()).decodeFromBytes(getTokenValue()); setTokenType(); } }
krbToken = new KrbToken(); krbToken.setTokenValue(tokenEncoder.encodeAsBytes(authToken)); } catch (KrbException e) { throw new RuntimeException("Failed to encode AuthToken", e); krbToken.setTokenValue(tokenStr.getBytes()); krbToken.setInnerToken(authToken); krbToken.setTokenType(); krbToken.setTokenFormat(TokenFormat.JWT);
/** * Get an identity's Authorization Data, invoked by getIdentityAuthorizationData. * @param kdcClientRequest The KdcClientRequest * @param encTicketPart The EncTicketPart being built for the KrbIdentity * @return The Authorization Data * @throws KrbException e */ protected AuthorizationData doGetIdentityAuthorizationData( KdcClientRequest kdcClientRequest, EncTicketPart encTicketPart) throws KrbException { if (kdcClientRequest.isToken()) { KrbToken krbToken = new KrbToken(kdcClientRequest.getToken(), TokenFormat.JWT); AdToken adToken = new AdToken(); adToken.setToken(krbToken); AuthorizationData authzData = new AuthorizationData(); AuthorizationDataEntry authzDataEntry = new AuthorizationDataEntry(); try { authzDataEntry.setAuthzData(adToken.encode()); } catch (IOException e) { throw new KrbException("Error encoding AdToken", e); } authzDataEntry.setAuthzType(AuthorizationType.AD_TOKEN); authzData.setElements(Collections.singletonList(authzDataEntry)); return authzData; } return null; }
public SgtTicket requestSgt(KrbToken token, String serverPrincipal, TgtTicket tgt) throws KrbException { if (!token.isAcToken()) { throw new IllegalArgumentException("Access token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_AC_TOKEN, token); requestOptions.add(KrbOption.TGT, tgt); requestOptions.add(KrbOption.SERVER_PRINCIPAL, serverPrincipal); return requestSgt(requestOptions); } }
/** * Request a TGT with user token credential and armor cache * @param token The KrbToken * @param armorCache The armor cache * @return TGT * @throws KrbException e */ public TgtTicket requestTgt(KrbToken token, String armorCache) throws KrbException { if (!token.isIdToken()) { throw new IllegalArgumentException("Identity token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_ID_TOKEN, token); requestOptions.add(KrbOption.ARMOR_CACHE, armorCache); return requestTgt(requestOptions); }
tokenPa.setToken(krbToken); TokenInfo info = new TokenInfo(); info.setTokenVendor(krbToken.getIssuer()); tokenPa.setTokenInfo(info);
krbToken = new KrbToken(); krbToken.setTokenValue(tokenEncoder.encodeAsBytes(authToken)); } catch (KrbException e) { throw new RuntimeException("Failed to encode AuthToken", e); krbToken.setTokenValue(tokenStr.getBytes()); krbToken.setInnerToken(authToken); krbToken.setTokenType(); krbToken.setTokenFormat(TokenFormat.JWT);
/** * Get an identity's Authorization Data, invoked by getIdentityAuthorizationData. * @param kdcClientRequest The KdcClientRequest * @param encTicketPart The EncTicketPart being built for the KrbIdentity * @return The Authorization Data * @throws KrbException e */ protected AuthorizationData doGetIdentityAuthorizationData( KdcClientRequest kdcClientRequest, EncTicketPart encTicketPart) throws KrbException { if (kdcClientRequest.isToken()) { KrbToken krbToken = new KrbToken(kdcClientRequest.getToken(), TokenFormat.JWT); AdToken adToken = new AdToken(); adToken.setToken(krbToken); AuthorizationData authzData = new AuthorizationData(); AuthorizationDataEntry authzDataEntry = new AuthorizationDataEntry(); try { authzDataEntry.setAuthzData(adToken.encode()); } catch (IOException e) { throw new KrbException("Error encoding AdToken", e); } authzDataEntry.setAuthzType(AuthorizationType.AD_TOKEN); authzData.setElements(Collections.singletonList(authzDataEntry)); return authzData; } return null; }
public SgtTicket requestSgt(KrbToken token, String serverPrincipal, TgtTicket tgt) throws KrbException { if (!token.isAcToken()) { throw new IllegalArgumentException("Access token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_AC_TOKEN, token); requestOptions.add(KrbOption.TGT, tgt); requestOptions.add(KrbOption.SERVER_PRINCIPAL, serverPrincipal); return requestSgt(requestOptions); } }
/** * Request a TGT with user token credential and tgt * @param token The KrbToken * @param tgt The tgt ticket * @return TGT * @throws KrbException e */ public TgtTicket requestTgt(KrbToken token, TgtTicket tgt) throws KrbException { if (!token.isIdToken()) { throw new IllegalArgumentException("Identity token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_ID_TOKEN, token); requestOptions.add(KrbOption.TGT, tgt); return requestTgt(requestOptions); }
tokenPa.setToken(krbToken); TokenInfo info = new TokenInfo(); info.setTokenVendor(krbToken.getIssuer()); tokenPa.setTokenInfo(info);
/** * Construct with prepared authToken and token format. * * @param authToken The authToken * @param format The token format */ public KrbToken(AuthToken authToken, TokenFormat format) { this(); this.innerToken = authToken; setTokenType(); setTokenFormat(format); try { setTokenValue(getTokenEncoder(format).encodeAsBytes(innerToken)); } catch (KrbException e) { throw new RuntimeException("Failed to encode AuthToken", e); } }
/** * {@inheritDoc} */ /* @Override public void decode(ByteBuffer content) throws IOException { super.decode(content); this.innerToken = getTokenDecoder().decodeFromBytes(getTokenValue()); setTokenType(); }*/ @Override public void decode(Asn1ParseResult parseResult) throws IOException { super.decode(parseResult); if (getTokenValue() != null) { this.innerToken = getTokenDecoder(getTokenFormat()).decodeFromBytes(getTokenValue()); setTokenType(); } }
public AsReq createAsReq(AuthToken authToken) throws KrbException { AsReq asReq = new AsReq(); KdcReqBody body = makeReqBody(); asReq.setReqBody(body); PaTokenRequest tokenPa = new PaTokenRequest(); KrbToken krbToken = new KrbToken(authToken, TokenFormat.JWT); tokenPa.setToken(krbToken); TokenInfo info = new TokenInfo(); info.setTokenVendor(authToken.getIssuer()); tokenPa.setTokenInfo(info); PaDataEntry paDataEntry = new PaDataEntry(); paDataEntry.setPaDataType(PaDataType.TOKEN_REQUEST); paDataEntry.setPaDataValue(KrbCodec.encode(tokenPa)); PaData paData = new PaData(); paData.addElement(paDataEntry); asReq.setPaData(paData); return asReq; }
/** * Request a service ticket using an Access Token. * @param token The KrbToken * @param serverPrincipal The server principal * @param armorCache The armor cache * @return service ticket * @throws KrbException e */ public SgtTicket requestSgt( KrbToken token, String serverPrincipal, String armorCache) throws KrbException { if (!token.isAcToken()) { throw new IllegalArgumentException("Access token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_AC_TOKEN, token); requestOptions.add(KrbOption.ARMOR_CACHE, armorCache); requestOptions.add(KrbOption.SERVER_PRINCIPAL, serverPrincipal); return requestSgt(requestOptions); }
/** * Request a TGT with user token credential and armor cache * @param token The KrbToken * @param armorCache The armor cache * @return TGT * @throws KrbException e */ public TgtTicket requestTgt(KrbToken token, String armorCache) throws KrbException { if (!token.isIdToken()) { throw new IllegalArgumentException("Identity token is expected"); } KOptions requestOptions = new KOptions(); requestOptions.add(TokenOption.USER_ID_TOKEN, token); requestOptions.add(KrbOption.ARMOR_CACHE, armorCache); return requestTgt(requestOptions); }
public AsReq createAsReq(AuthToken authToken) throws KrbException { AsReq asReq = new AsReq(); KdcReqBody body = makeReqBody(); asReq.setReqBody(body); PaTokenRequest tokenPa = new PaTokenRequest(); KrbToken krbToken = new KrbToken(authToken, TokenFormat.JWT); tokenPa.setToken(krbToken); TokenInfo info = new TokenInfo(); info.setTokenVendor(authToken.getIssuer()); tokenPa.setTokenInfo(info); PaDataEntry paDataEntry = new PaDataEntry(); paDataEntry.setPaDataType(PaDataType.TOKEN_REQUEST); paDataEntry.setPaDataValue(KrbCodec.encode(tokenPa)); PaData paData = new PaData(); paData.addElement(paDataEntry); asReq.setPaData(paData); return asReq; }