use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class SAML2ClientTests method testSaml2ConfigurationOfKeyStore.
@Test
public void testSaml2ConfigurationOfKeyStore() 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("testKeystore.jks", "pac4j-test-passwd", "pac4j-test-passwd", "resource: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());
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class SAML2Utils method buildChainingMetadataResolver.
public static ChainingMetadataResolver buildChainingMetadataResolver(final SAML2MetadataResolver idpMetadataProvider, final SAML2MetadataResolver spMetadataProvider) {
final var metadataManager = new ChainingMetadataResolver();
metadataManager.setId(ChainingMetadataResolver.class.getCanonicalName());
try {
final List<MetadataResolver> list = new ArrayList<>();
list.add(idpMetadataProvider.resolve());
list.add(spMetadataProvider.resolve());
metadataManager.setResolvers(list);
metadataManager.initialize();
} catch (final ResolverException e) {
throw new TechnicalException("Error adding idp or sp metadatas to manager", e);
} catch (final ComponentInitializationException e) {
throw new TechnicalException("Error initializing manager", e);
}
return metadataManager;
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class SAML2IdentityProviderMetadataResolverTest method resolveMetadataOverUrlWithHostnameVerifier.
@Test
public void resolveMetadataOverUrlWithHostnameVerifier() throws Exception {
var configuration = new SAML2Configuration();
configuration.setIdentityProviderMetadataResource(new UrlResource("https://self-signed.badssl.com"));
metadataResolver = new SAML2IdentityProviderMetadataResolver(configuration);
try {
metadataResolver.init();
} catch (final TechnicalException e) {
assertEquals(SSLHandshakeException.class, e.getCause().getClass());
}
metadataResolver.setHostnameVerifier((s, sslSession) -> true);
metadataResolver.setSslSocketFactory(disabledSslContext().getSocketFactory());
try {
metadataResolver.init();
} catch (final TechnicalException e) {
assertEquals(XMLParserException.class, e.getCause().getClass());
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class OAuthCredentialsExtractor method extract.
@Override
public Optional<Credentials> extract(final WebContext context, final SessionStore sessionStore) {
final boolean hasBeenCancelled = (Boolean) configuration.getHasBeenCancelledFactory().apply(context);
// check if the authentication has been cancelled
if (hasBeenCancelled) {
logger.debug("authentication has been cancelled by user");
return Optional.empty();
}
// check errors
try {
var errorFound = false;
final var oauthCredentialsException = new OAuthCredentialsException("Failed to retrieve OAuth credentials, error parameters found");
for (final var key : OAuthCredentialsException.ERROR_NAMES) {
final var value = context.getRequestParameter(key);
if (value.isPresent()) {
errorFound = true;
oauthCredentialsException.setErrorMessage(key, value.get());
}
}
if (errorFound) {
throw oauthCredentialsException;
} else {
return getOAuthCredentials(context, sessionStore);
}
} catch (final OAuthException e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class OAuth10RedirectionActionBuilder method getRedirectionAction.
@Override
public Optional<RedirectionAction> getRedirectionAction(final WebContext context, final SessionStore sessionStore) {
try {
final var service = (OAuth10aService) this.configuration.buildService(context, client);
final OAuth1RequestToken requestToken;
try {
requestToken = service.getRequestToken();
} catch (final IOException | InterruptedException | ExecutionException e) {
throw new HttpCommunicationException("Error getting token: " + e.getMessage());
}
logger.debug("requestToken: {}", requestToken);
// save requestToken in user session
sessionStore.set(context, configuration.getRequestTokenSessionAttributeName(client.getName()), requestToken);
final var authorizationUrl = service.getAuthorizationUrl(requestToken);
logger.debug("authorizationUrl: {}", authorizationUrl);
return Optional.of(HttpActionHelper.buildRedirectUrlAction(context, authorizationUrl));
} catch (final OAuthException e) {
throw new TechnicalException(e);
}
}
Aggregations