Search in sources :

Example 1 with OauthTokenIssuerImpl

use of org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl in project identity-inbound-auth-oauth by wso2-extensions.

the class UserInfoResponseBaseTest method mockObjectsRelatedToTokenValidation.

protected void mockObjectsRelatedToTokenValidation() throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(OAuthServerConfiguration.getInstance().getOAuthTokenGenerator()).thenReturn(oAuthIssuer);
    when(OAuthServerConfiguration.getInstance().getSignatureAlgorithm()).thenReturn("SHA256withRSA");
    when(OAuth2Util.getAccessTokenIdentifier(any())).thenCallRealMethod();
    when(OAuth2Util.findAccessToken(anyString(), anyBoolean())).thenCallRealMethod();
    when(OAuth2Util.class, "getAccessTokenDOFromMatchingTokenIssuer", anyString(), anyMap(), anyBoolean()).thenCallRealMethod();
    AccessTokenDO accessTokenDO = new AccessTokenDO();
    accessTokenDO.setAccessToken(accessToken);
    when(OAuth2Util.getAccessTokenDOFromTokenIdentifier(anyString(), anyBoolean())).thenReturn(accessTokenDO);
    Map<String, OauthTokenIssuer> oauthTokenIssuerMap = new HashMap<>();
    oauthTokenIssuerMap.put(DEFAULT_TOKEN_TYPE, new OauthTokenIssuerImpl());
    oauthTokenIssuerMap.put(JWT_TOKEN_TYPE, new JWTTokenIssuer());
    when(OAuthServerConfiguration.getInstance().getOauthTokenIssuerMap()).thenReturn(oauthTokenIssuerMap);
}
Also used : AccessTokenDO(org.wso2.carbon.identity.oauth2.model.AccessTokenDO) OauthTokenIssuer(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuer) JWTTokenIssuer(org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer) HashMap(java.util.HashMap) OAuth2Util(org.wso2.carbon.identity.oauth2.util.OAuth2Util) OauthTokenIssuerImpl(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl) Matchers.anyString(org.mockito.Matchers.anyString)

Example 2 with OauthTokenIssuerImpl

use of org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl in project identity-inbound-auth-oauth by wso2-extensions.

the class TokenValidationHandlerTest method mockRequiredObjects.

protected void mockRequiredObjects() throws Exception {
    mockStatic(OAuthServerConfiguration.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(OAuthServerConfiguration.getInstance().getOAuthTokenGenerator()).thenReturn(oAuthIssuer);
    when(OAuthServerConfiguration.getInstance().getSignatureAlgorithm()).thenReturn("SHA256withRSA");
    when(OAuthServerConfiguration.getInstance().getHashAlgorithm()).thenReturn("SHA-256");
    Map<String, OauthTokenIssuer> oauthTokenIssuerMap = new HashMap<>();
    oauthTokenIssuerMap.put(DEFAULT_TOKEN_TYPE, new OauthTokenIssuerImpl());
    oauthTokenIssuerMap.put(JWT_TOKEN_TYPE, new JWTTokenIssuer());
    when(OAuthServerConfiguration.getInstance().getOauthTokenIssuerMap()).thenReturn(oauthTokenIssuerMap);
    mockStatic(IdentityDatabaseUtil.class);
    when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(getDBConnection());
    when(IdentityDatabaseUtil.getDBConnection()).thenReturn(getDBConnection());
}
Also used : OauthTokenIssuer(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuer) JWTTokenIssuer(org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer) HashMap(java.util.HashMap) OauthTokenIssuerImpl(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl)

Example 3 with OauthTokenIssuerImpl

use of org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl in project identity-inbound-auth-oauth by wso2-extensions.

the class AbstractAuthorizationGrantHandlerTest method setUp.

@BeforeMethod
public void setUp() throws IdentityOAuthAdminException, IdentityOAuth2Exception {
    authenticatedUser = new AuthenticatedUser() {
    };
    OAuthComponentServiceHolder.getInstance().setRealmService(IdentityTenantUtil.getRealmService());
    authenticatedUser.setUserName("randomUser");
    authenticatedUser.setTenantDomain("Homeless");
    authenticatedUser.setUserStoreDomain("Street");
    authenticatedUser.setUserId("4b4414e1-916b-4475-aaee-6b0751c29ff6");
    clientId = UUID.randomUUID().toString();
    tokenId = clientId;
    appId = clientId;
    oauthIssuer = new OauthTokenIssuerImpl();
    handler = new MockAuthzGrantHandler();
    handler.init();
    OAuthAppDAO oAuthAppDAO = new OAuthAppDAO();
    oAuthAppDO = new OAuthAppDO();
    oAuthAppDO.setApplicationName(appId);
    oAuthAppDO.setOauthConsumerKey(clientId);
    oAuthAppDO.setUser(authenticatedUser);
    oAuthAppDO.setCallbackUrl("http://i.have.nowhere.to.go");
    oAuthAppDO.setOauthVersion(OAuthConstants.OAuthVersions.VERSION_2);
    oAuthAppDAO.addOAuthApplication(oAuthAppDO);
}
Also used : OAuthAppDAO(org.wso2.carbon.identity.oauth.dao.OAuthAppDAO) OAuthAppDO(org.wso2.carbon.identity.oauth.dao.OAuthAppDO) OauthTokenIssuerImpl(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with OauthTokenIssuerImpl

use of org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl in project identity-inbound-auth-oauth by wso2-extensions.

the class SAML2BearerGrantHandlerTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    System.setProperty(CarbonBaseConstants.CARBON_HOME, Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString());
    mockStatic(OAuthServerConfiguration.class);
    mockStatic(IdentityUtil.class);
    mockStatic(UnmarshallUtils.class);
    when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
    when(oAuthServerConfiguration.getIdentityOauthTokenIssuer()).thenReturn(oauthIssuer);
    when(oAuthServerConfiguration.getPersistenceProcessor()).thenReturn(persistenceProcessor);
    federatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
    saml2BearerGrantHandler = new SAML2BearerGrantHandler();
    saml2BearerGrantHandler.init();
    oAuth2AccessTokenReqDTO = new OAuth2AccessTokenReqDTO();
    oAuth2AccessTokenReqDTO.setScope(SCOPE_ARRAY);
    tokReqMsgCtx = new OAuthTokenReqMessageContext(oAuth2AccessTokenReqDTO);
    tokReqMsgCtx.setTenantID(-1234);
    oauthIssuer = new OauthTokenIssuerImpl();
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) OAuthTokenReqMessageContext(org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext) OauthTokenIssuerImpl(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl) OAuth2AccessTokenReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 5 with OauthTokenIssuerImpl

use of org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuthServerConfiguration method getIdentityOauthTokenIssuer.

/**
 * Returns server level default identity oauth token issuer
 *
 * @return instance of default identity oauth token issuer
 */
public OauthTokenIssuer getIdentityOauthTokenIssuer() {
    if (oauthIdentityTokenGenerator == null) {
        synchronized (this) {
            if (oauthIdentityTokenGenerator == null) {
                try {
                    if (oauthIdentityTokenGeneratorClassName != null) {
                        Class clazz = this.getClass().getClassLoader().loadClass(oauthIdentityTokenGeneratorClassName);
                        oauthIdentityTokenGenerator = (OauthTokenIssuer) clazz.newInstance();
                        log.info("An instance of " + oauthIdentityTokenGeneratorClassName + " is created for Identity OAuth token generation.");
                    } else {
                        oauthIdentityTokenGenerator = new OauthTokenIssuerImpl();
                        log.info("The default Identity OAuth token issuer will be used. No custom token " + "generator is set.");
                    }
                } catch (Exception e) {
                    String errorMsg = "Error when instantiating the OAuthIssuer : " + tokenPersistenceProcessorClassName + ". Defaulting to OAuthIssuerImpl";
                    log.error(errorMsg, e);
                    oauthIdentityTokenGenerator = new OauthTokenIssuerImpl();
                }
            }
        }
    }
    return oauthIdentityTokenGenerator;
}
Also used : OauthTokenIssuerImpl(org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)

Aggregations

OauthTokenIssuerImpl (org.wso2.carbon.identity.oauth2.token.OauthTokenIssuerImpl)6 OauthTokenIssuer (org.wso2.carbon.identity.oauth2.token.OauthTokenIssuer)3 HashMap (java.util.HashMap)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)2 JWTTokenIssuer (org.wso2.carbon.identity.oauth2.token.JWTTokenIssuer)2 Matchers.anyString (org.mockito.Matchers.anyString)1 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)1 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)1 OAuthAppDAO (org.wso2.carbon.identity.oauth.dao.OAuthAppDAO)1 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)1 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)1 OAuth2AccessTokenReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO)1 OAuthTokenReqMessageContext (org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext)1 OAuth2Util (org.wso2.carbon.identity.oauth2.util.OAuth2Util)1