use of org.wso2.carbon.identity.oauth2.model.TokenIssuerDO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServerConfiguration method parseSupportedTokenTypesConfig.
private void parseSupportedTokenTypesConfig(OMElement oauthConfigElem) {
OMElement supportedTokenTypesElem = oauthConfigElem.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements.SUPPORTED_TOKEN_TYPES));
if (supportedTokenTypesElem != null) {
Iterator<OMElement> iterator = supportedTokenTypesElem.getChildrenWithName(getQNameWithIdentityNS(ConfigElements.SUPPORTED_TOKEN_TYPE));
while (iterator.hasNext()) {
OMElement supportedTokenTypeElement = iterator.next();
OMElement tokenTypeNameElement = supportedTokenTypeElement.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements.TOKEN_TYPE_NAME));
String tokenTypeName = null;
if (tokenTypeNameElement != null) {
tokenTypeName = tokenTypeNameElement.getText();
}
OMElement tokenTypeImplClassElement = supportedTokenTypeElement.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements.TOKEN_TYPE_IMPL_CLASS));
String tokenTypeImplClass = null;
if (tokenTypeImplClassElement != null) {
tokenTypeImplClass = tokenTypeImplClassElement.getText();
}
OMElement persistAccessTokenAliasElement = supportedTokenTypeElement.getFirstChildWithName(getQNameWithIdentityNS(ConfigElements.IDENTITY_OAUTH_PERSIST_TOKEN_ALIAS));
String persistAccessTokenAlias = null;
if (persistAccessTokenAliasElement != null) {
persistAccessTokenAlias = persistAccessTokenAliasElement.getText();
}
if (StringUtils.isNotEmpty(tokenTypeName)) {
TokenIssuerDO tokenIssuerDO = new TokenIssuerDO();
if (StringUtils.isNotEmpty(tokenTypeImplClass)) {
tokenIssuerDO.setTokenType(tokenTypeName);
tokenIssuerDO.setTokenImplClass(tokenTypeImplClass);
}
if (StringUtils.isNotEmpty(persistAccessTokenAlias)) {
tokenIssuerDO.setPersistAccessTokenAlias(Boolean.valueOf(persistAccessTokenAlias));
} else {
tokenIssuerDO.setPersistAccessTokenAlias(true);
}
supportedTokenIssuers.put(tokenTypeName, tokenIssuerDO);
}
}
}
boolean isRegistered = false;
// Adding global token issuer configured in the identity xml as a supported token issuer
for (Map.Entry<String, TokenIssuerDO> entry : supportedTokenIssuers.entrySet()) {
TokenIssuerDO issuerDO = entry.getValue();
if (oauthIdentityTokenGeneratorClassName != null && oauthIdentityTokenGeneratorClassName.equals(issuerDO.getTokenImplClass())) {
isRegistered = true;
break;
}
}
if (!isRegistered && oauthIdentityTokenGeneratorClassName != null) {
boolean isPersistTokenAlias = true;
if (persistAccessTokenAlias != null) {
isPersistTokenAlias = Boolean.parseBoolean(persistAccessTokenAlias);
}
// If a server level <IdentityOAuthTokenGenerator> is defined, that will be our first choice for the
// "Default" token type issuer implementation.
supportedTokenIssuers.put(DEFAULT_TOKEN_TYPE, new TokenIssuerDO(DEFAULT_TOKEN_TYPE, oauthIdentityTokenGeneratorClassName, isPersistTokenAlias));
}
// Adding default token types if not added in the configuration.
if (!supportedTokenIssuers.containsKey(DEFAULT_TOKEN_TYPE)) {
supportedTokenIssuers.put(DEFAULT_TOKEN_TYPE, new TokenIssuerDO(DEFAULT_TOKEN_TYPE, DEFAULT_OAUTH_TOKEN_ISSUER_CLASS, true));
}
if (!supportedTokenIssuers.containsKey(JWT_TOKEN_TYPE)) {
supportedTokenIssuers.put(JWT_TOKEN_TYPE, new TokenIssuerDO(JWT_TOKEN_TYPE, JWT_TOKEN_ISSUER_CLASS, true));
}
// Create the token types list.
supportedTokenTypes.addAll(supportedTokenIssuers.keySet());
}
use of org.wso2.carbon.identity.oauth2.model.TokenIssuerDO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServerConfiguration method populateOAuthTokenIssuerMap.
/**
* This method populates oauthTokenIssuerMap by reading the supportedTokenIssuers map. Earlier we only
* populated the oauthTokenIssuerMap when a token is issued but now we use this map for token validation
* calls as well.
*/
public void populateOAuthTokenIssuerMap() throws IdentityOAuth2Exception {
if (supportedTokenIssuers != null) {
for (Map.Entry<String, TokenIssuerDO> tokenIssuerDO : supportedTokenIssuers.entrySet()) {
try {
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(tokenIssuerDO.getValue().getTokenImplClass());
OauthTokenIssuer oauthTokenIssuer = (OauthTokenIssuer) clazz.newInstance();
oauthTokenIssuer.setPersistAccessTokenAlias(tokenIssuerDO.getValue().isPersistAccessTokenAlias());
oauthTokenIssuerMap.put(tokenIssuerDO.getKey(), oauthTokenIssuer);
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new IdentityOAuth2Exception("Error while populating OAuth Token Issuer Map. Issuer key: " + tokenIssuerDO.getKey() + ", Issuer value: " + tokenIssuerDO.getValue(), e);
}
}
} else {
throw new IdentityOAuth2Exception("supportedTokenIssuers map returned null when populating the " + "oauthTokenIssuerMap object.");
}
}
use of org.wso2.carbon.identity.oauth2.model.TokenIssuerDO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthServerConfiguration method addAndReturnTokenIssuerInstance.
/**
* Adds oauth token issuer instances used for token generation.
* @param tokenType registered token type
* @return token issuer instance
* @throws IdentityOAuth2Exception
*/
public OauthTokenIssuer addAndReturnTokenIssuerInstance(String tokenType) throws IdentityOAuth2Exception {
TokenIssuerDO tokenIssuerDO = supportedTokenIssuers.get(tokenType);
OauthTokenIssuer oauthTokenIssuer = null;
if (tokenIssuerDO != null && tokenIssuerDO.getTokenImplClass() != null) {
try {
if (oauthTokenIssuerMap.get(tokenType) == null) {
Class clazz = this.getClass().getClassLoader().loadClass(tokenIssuerDO.getTokenImplClass());
oauthTokenIssuer = (OauthTokenIssuer) clazz.newInstance();
oauthTokenIssuer.setPersistAccessTokenAlias(supportedTokenIssuers.get(tokenType).isPersistAccessTokenAlias());
oauthTokenIssuerMap.put(tokenType, oauthTokenIssuer);
log.info("An instance of " + tokenIssuerDO.getTokenImplClass() + " is created for Identity OAuth token generation.");
} else {
oauthTokenIssuer = oauthTokenIssuerMap.get(tokenType);
}
} catch (Exception e) {
String errorMsg = "Error when instantiating the OAuthIssuer : " + tokenIssuerDO.getTokenImplClass() + ". Defaulting to OAuthIssuerImpl";
throw new IdentityOAuth2Exception(errorMsg, e);
}
}
return oauthTokenIssuer;
}
Aggregations