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);
}
}
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);
}
}
}
}
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());
}
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);
}
}
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());
}
Aggregations