Search in sources :

Example 6 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class ConfigurationFactory method destroyCryptoProviderInstance.

private void destroyCryptoProviderInstance() {
    log.trace("Destroyed crypto provider instance.");
    AbstractCryptoProvider abstractCryptoProvider = abstractCryptoProviderInstance.get();
    abstractCryptoProviderInstance.destroy(abstractCryptoProvider);
    CryptoProviderFactory.reset();
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider)

Example 7 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class ConfigurationFactory method createFromLdap.

private boolean createFromLdap(boolean recoverFromFiles) {
    log.info("Loading configuration from '{}' DB...", baseConfiguration.getString("persistence.type"));
    try {
        final io.jans.as.model.config.Conf c = loadConfigurationFromPersistence();
        if (c != null) {
            init(c);
            // Destroy old configuration
            if (this.loaded) {
                destroy(AppConfiguration.class);
                destroy(io.jans.as.model.config.StaticConfiguration.class);
                destroy(io.jans.as.model.config.WebKeysConfiguration.class);
                destroy(ErrorResponseFactory.class);
            }
            this.loaded = true;
            configurationUpdateEvent.select(ConfigurationUpdate.Literal.INSTANCE).fire(conf);
            destroyCryptoProviderInstance();
            AbstractCryptoProvider newAbstractCryptoProvider = abstractCryptoProviderInstance.get();
            cryptoProviderEvent.select(CryptoProviderEvent.Literal.INSTANCE).fire(newAbstractCryptoProvider);
            return true;
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    if (recoverFromFiles) {
        log.info("Unable to find configuration in LDAP, try to load configuration from file system... ");
        if (createFromFile()) {
            this.loadedFromLdap = false;
            return true;
        }
    }
    return false;
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) Conf(io.jans.as.model.config.Conf) ConfigurationException(io.jans.exception.ConfigurationException) BasePersistenceException(io.jans.orm.exception.BasePersistenceException)

Example 8 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class SubjectIdentifierGenerator method generatePairwiseSubjectIdentifier.

public static String generatePairwiseSubjectIdentifier(String sectorIdentifier, String localAccountId, String key, String salt, AppConfiguration configuration) throws Exception {
    AbstractCryptoProvider cryptoProvider = CryptoProviderFactory.getCryptoProvider(configuration);
    String signingInput = sectorIdentifier + localAccountId + salt;
    return cryptoProvider.sign(signingInput, null, key, SignatureAlgorithm.HS256);
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider)

Example 9 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class ConfigurationFactory method destroyCryptoProviderInstance.

public void destroyCryptoProviderInstance(Class<? extends AbstractCryptoProvider> clazz) {
    AbstractCryptoProvider abstractCryptoProvider = abstractCryptoProviderInstance.get();
    abstractCryptoProviderInstance.destroy(abstractCryptoProvider);
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider)

Example 10 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class OpenIDRequestObjectHttpTest method requestParameterMethodAlgNone.

@Parameters({ "userId", "userSecret", "redirectUri", "redirectUris", "sectorIdentifierUri" })
@Test
public void requestParameterMethodAlgNone(final String userId, final String userSecret, final String redirectUri, final String redirectUris, final String sectorIdentifierUri) {
    try {
        showTitle("requestParameterMethodAlgNone");
        List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
        // 1. Dynamic Client Registration
        RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
        registerRequest.setResponseTypes(responseTypes);
        registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.NONE);
        registerRequest.addCustomAttribute("jansTrustedClnt", "true");
        registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
        RegisterClient registerClient = new RegisterClient(registrationEndpoint);
        registerClient.setRequest(registerRequest);
        RegisterResponse response = registerClient.exec();
        showClient(registerClient);
        assertRegisterResponseOk(response, 201, true);
        String clientId = response.getClientId();
        // 2. Request authorization
        AbstractCryptoProvider cryptoProvider = createCryptoProviderWithAllowedNone();
        List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
        String nonce = UUID.randomUUID().toString();
        String state = UUID.randomUUID().toString();
        AuthorizationRequest request = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
        request.setState(state);
        request.setAuthUsername(userId);
        request.setAuthPassword(userSecret);
        request.getPrompts().add(Prompt.NONE);
        JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(request, SignatureAlgorithm.NONE, cryptoProvider);
        jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull()));
        jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false)));
        jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull()));
        jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull()));
        jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false)));
        jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull()));
        jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, ClaimValue.createValueList(new String[] { ACR_VALUE })));
        jwtAuthorizationRequest.getIdTokenMember().setMaxAge(86400);
        String authJwt = jwtAuthorizationRequest.getEncodedJwt();
        request.setRequest(authJwt);
        AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
        authorizeClient.setRequest(request);
        AuthorizationResponse response1 = authorizeClient.exec();
        showClient(authorizeClient);
        assertEquals(response1.getStatus(), 302, "Unexpected response code: " + response1.getStatus());
        assertNotNull(response1.getLocation(), "The location is null");
        assertNotNull(response1.getAccessToken(), "The accessToken is null");
        assertNotNull(response1.getTokenType(), "The tokenType is null");
        assertNotNull(response1.getIdToken(), "The idToken is null");
        assertNotNull(response1.getState(), "The state is null");
        String accessToken = response1.getAccessToken();
        // 3. Request user info
        UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint);
        UserInfoResponse response3 = userInfoClient.execUserInfo(accessToken);
        showClient(userInfoClient);
        assertUserInfoBasicMinimumResponseOk(response3, 200);
        assertUserInfoPersonalDataNotNull(response3);
        assertNotNull(response3.getClaim(JwtClaimName.ADDRESS));
    } catch (Exception e) {
        fail(e.getMessage(), e);
    }
}
Also used : RegisterRequest(io.jans.as.client.RegisterRequest) AuthorizationRequest(io.jans.as.client.AuthorizationRequest) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) UserInfoClient(io.jans.as.client.UserInfoClient) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) ResponseType(io.jans.as.model.common.ResponseType) AuthorizationResponse(io.jans.as.client.AuthorizationResponse) RegisterResponse(io.jans.as.client.RegisterResponse) RegisterClient(io.jans.as.client.RegisterClient) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) UserInfoResponse(io.jans.as.client.UserInfoResponse) AuthorizeClient(io.jans.as.client.AuthorizeClient) Claim(io.jans.as.client.model.authorize.Claim) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.client.BaseTest)

Aggregations

AbstractCryptoProvider (io.jans.as.model.crypto.AbstractCryptoProvider)23 Test (org.testng.annotations.Test)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 ResponseType (io.jans.as.model.common.ResponseType)7 BaseTest (io.jans.as.client.BaseTest)6 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)6 Jwt (io.jans.as.model.jwt.Jwt)6 AuthorizationRequest (io.jans.as.client.AuthorizationRequest)5 AuthorizationResponse (io.jans.as.client.AuthorizationResponse)5 RegisterClient (io.jans.as.client.RegisterClient)5 RegisterRequest (io.jans.as.client.RegisterRequest)5 RegisterResponse (io.jans.as.client.RegisterResponse)5 Parameters (org.testng.annotations.Parameters)5 UserInfoClient (io.jans.as.client.UserInfoClient)4 UserInfoResponse (io.jans.as.client.UserInfoResponse)4 Claim (io.jans.as.client.model.authorize.Claim)4 JwtAuthorizationRequest (io.jans.as.client.model.authorize.JwtAuthorizationRequest)4 PlainTextSignature (io.jans.as.model.jws.PlainTextSignature)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3