Search in sources :

Example 71 with TechnicalException

use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.

the class CasConfiguration method internalInit.

@Override
protected void internalInit(final boolean forceReinit) {
    if (CommonHelper.isBlank(this.loginUrl) && CommonHelper.isBlank(this.prefixUrl) && CommonHelper.isBlank(this.restUrl)) {
        throw new TechnicalException("loginUrl, prefixUrl and restUrl cannot be all blank");
    }
    if (urlResolver == null) {
        urlResolver = new DefaultUrlResolver();
    }
    initializeClientConfiguration();
    initializeLogoutHandler();
    if (privateKeyPath != null) {
        final String algo;
        if (privateKeyAlgorithm != null) {
            algo = privateKeyAlgorithm;
        } else {
            algo = "RSA";
        }
        this.privateKey = PrivateKeyUtils.createKey(privateKeyPath, algo);
    }
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver)

Example 72 with TechnicalException

use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.

the class DbAuthenticatorBuilder method tryBuildDbAuthenticator.

public void tryBuildDbAuthenticator(final Map<String, Authenticator> authenticators, final Map<String, PasswordEncoder> encoders) {
    for (var i = 0; i <= MAX_NUM_AUTHENTICATORS; i++) {
        if (containsProperty(DB_DATASOURCE_CLASS_NAME, i) || containsProperty(DB_JDBC_URL, i)) {
            try {
                final var ds = buildDataSource(i);
                final var authenticator = new DbProfileService(ds);
                if (containsProperty(DB_ATTRIBUTES, i)) {
                    authenticator.setAttributes(getProperty(DB_ATTRIBUTES, i));
                }
                if (containsProperty(DB_USER_ID_ATTRIBUTE, i)) {
                    authenticator.setIdAttribute(getProperty(DB_USER_ID_ATTRIBUTE, i));
                }
                if (containsProperty(DB_USERNAME_ATTRIBUTE, i)) {
                    authenticator.setUsernameAttribute(getProperty(DB_USERNAME_ATTRIBUTE, i));
                }
                if (containsProperty(DB_USER_PASSWORD_ATTRIBUTE, i)) {
                    authenticator.setPasswordAttribute(getProperty(DB_USER_PASSWORD_ATTRIBUTE, i));
                }
                if (containsProperty(DB_USERS_TABLE, i)) {
                    authenticator.setUsersTable(getProperty(DB_USERS_TABLE, i));
                }
                if (containsProperty(DB_PASSWORD_ENCODER, i)) {
                    authenticator.setPasswordEncoder(encoders.get(getProperty(DB_PASSWORD_ENCODER, i)));
                }
                authenticators.put(concat("db", i), authenticator);
            } catch (final SQLException e) {
                throw new TechnicalException(e);
            }
        }
    }
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) SQLException(java.sql.SQLException) DbProfileService(org.pac4j.sql.profile.service.DbProfileService)

Example 73 with TechnicalException

use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.

the class DirectCasProxyClientTests method testTokenExistsValidationOccurs.

@Test
public void testTokenExistsValidationOccurs() {
    final var configuration = new CasConfiguration();
    configuration.setLoginUrl(LOGIN_URL);
    configuration.setProtocol(CasProtocol.CAS30_PROXY);
    configuration.setDefaultTicketValidator((ticket, service) -> {
        if (TICKET.equals(ticket) && CALLBACK_URL.equals(service)) {
            return new AssertionImpl(TICKET);
        }
        throw new TechnicalException("Bad ticket or service");
    });
    final var client = new DirectCasProxyClient(configuration, CALLBACK_URL);
    final var context = MockWebContext.create();
    context.setFullRequestURL(CALLBACK_URL + "?" + CasConfiguration.TICKET_PARAMETER + "=" + TICKET);
    context.addRequestParameter(CasConfiguration.TICKET_PARAMETER, TICKET);
    final var credentials = (TokenCredentials) client.getCredentials(context, new MockSessionStore()).get();
    assertEquals(TICKET, credentials.getToken());
    final var profile = credentials.getUserProfile();
    assertTrue(profile instanceof CasProfile);
    assertEquals(TICKET, profile.getId());
}
Also used : AssertionImpl(org.jasig.cas.client.validation.AssertionImpl) CasProfile(org.pac4j.cas.profile.CasProfile) TechnicalException(org.pac4j.core.exception.TechnicalException) MockSessionStore(org.pac4j.core.context.session.MockSessionStore) CasConfiguration(org.pac4j.cas.config.CasConfiguration) TokenCredentials(org.pac4j.core.credentials.TokenCredentials) Test(org.junit.Test)

Example 74 with TechnicalException

use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.

the class ConfigBuilder method build.

@SuppressWarnings("unchecked")
public static synchronized Config build(final String factoryName, final Object... parameters) {
    try {
        logger.info("Build the configuration from factory: {}", factoryName);
        var tccl = Thread.currentThread().getContextClassLoader();
        final Class<ConfigFactory> clazz;
        if (tccl == null) {
            clazz = (Class<ConfigFactory>) Class.forName(factoryName);
        } else {
            clazz = (Class<ConfigFactory>) Class.forName(factoryName, true, tccl);
        }
        final var factory = clazz.getDeclaredConstructor().newInstance();
        return factory.build(parameters);
    } catch (final Exception e) {
        throw new TechnicalException("Cannot build configuration", e);
    }
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) TechnicalException(org.pac4j.core.exception.TechnicalException)

Example 75 with TechnicalException

use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.

the class SAML2ClientTests method testSaml2ConfigurationOfKeyStoreUsingResource.

@Test
public void testSaml2ConfigurationOfKeyStoreUsingResource() throws IOException {
    final Resource rs = new FileSystemResource("testKeystore.jks");
    if (rs.exists() && !rs.getFile().delete()) {
        throw new TechnicalException("File could not be deleted");
    }
    final var cfg = new SAML2Configuration(new FileSystemResource("testKeystore.jks"), "pac4j-test-passwd", "pac4j-test-passwd", new ClassPathResource("testshib-providers.xml"));
    cfg.init();
    final var p = new KeyStoreCredentialProvider(cfg);
    assertNotNull(p.getKeyInfoGenerator());
    assertNotNull(p.getCredentialResolver());
    assertNotNull(p.getKeyInfo());
    assertNotNull(p.getKeyInfoCredentialResolver());
    assertNotNull(p.getCredential());
}
Also used : TechnicalException(org.pac4j.core.exception.TechnicalException) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) KeyStoreCredentialProvider(org.pac4j.saml.crypto.KeyStoreCredentialProvider) UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

TechnicalException (org.pac4j.core.exception.TechnicalException)81 IOException (java.io.IOException)26 URI (java.net.URI)7 URISyntaxException (java.net.URISyntaxException)7 HashMap (java.util.HashMap)7 OAuthException (com.github.scribejava.core.exceptions.OAuthException)6 JWT (com.nimbusds.jwt.JWT)6 ParseException (com.nimbusds.oauth2.sdk.ParseException)6 HttpURLConnection (java.net.HttpURLConnection)6 Test (org.junit.Test)6 OidcCredentials (org.pac4j.oidc.credentials.OidcCredentials)6 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)5 SignedJWT (com.nimbusds.jwt.SignedJWT)5 ArrayList (java.util.ArrayList)5 ComponentInitializationException (net.shibboleth.utilities.java.support.component.ComponentInitializationException)5 JOSEException (com.nimbusds.jose.JOSEException)4 URL (java.net.URL)4 HTTPRequest (com.nimbusds.oauth2.sdk.http.HTTPRequest)3 HTTPResponse (com.nimbusds.oauth2.sdk.http.HTTPResponse)3 AccessToken (com.nimbusds.oauth2.sdk.token.AccessToken)3