use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class RSASignatureConfiguration method sign.
@Override
public SignedJWT sign(JWTClaimsSet claims) {
init();
CommonHelper.assertNotNull("privateKey", privateKey);
try {
final JWSSigner signer = new RSASSASigner(this.privateKey);
final var signedJWT = new SignedJWT(new JWSHeader(algorithm), claims);
signedJWT.sign(signer);
return signedJWT;
} catch (final JOSEException e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class SunJaasKerberosTicketValidator method internalInit.
@Override
protected void internalInit(final boolean forceReinit) {
// then internalInit() runs lazily during the first validateTicket() call
try {
CommonHelper.assertNotNull("servicePrincipal must be specified", this.servicePrincipal);
CommonHelper.assertNotNull("keyTab must be specified", this.keyTabLocation);
var keyTabLocationAsString = this.keyTabLocation.getURL().toExternalForm();
// As Java 6 accepts it with and without the prefix, we don't need to check for Java 7
if (keyTabLocationAsString.startsWith("file:")) {
keyTabLocationAsString = keyTabLocationAsString.substring(5);
}
var loginConfig = new LoginConfig(keyTabLocationAsString, this.servicePrincipal, this.debug);
Set<Principal> princ = new HashSet<>(1);
princ.add(new KerberosPrincipal(this.servicePrincipal));
var sub = new Subject(false, princ, new HashSet<>(), new HashSet<>());
var lc = new LoginContext("", sub, null, loginConfig);
lc.login();
this.serviceSubject = lc.getSubject();
} catch (final LoginException | IOException e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class SAML2HttpClientBuilder method build.
public HttpClient build() {
try {
final var builder = new Pac4jHttpClientBuilder();
builder.resetDefaults();
if (this.connectionTimeout != null) {
builder.setConnectionTimeout(this.connectionTimeout);
}
builder.setUseSystemProperties(this.useSystemProperties);
if (this.socketTimeout != null) {
builder.setSocketTimeout(this.socketTimeout);
}
builder.setHttpFollowRedirects(this.followRedirects);
builder.setMaxConnectionsTotal(this.maxConnectionsTotal);
builder.setConnectionCloseAfterResponse(this.closeConnectionAfterResponse);
if (this.credentialsProvider != null) {
builder.getApacheBuilder().setDefaultCredentialsProvider(credentialsProvider);
}
return builder.buildClient();
} catch (final Exception e) {
throw new TechnicalException(e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class VelocityEngineFactory method getEngine.
public static VelocityEngine getEngine() {
try {
final var props = new Properties();
props.putAll(net.shibboleth.utilities.java.support.velocity.VelocityEngine.getDefaultProperties());
props.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8");
props.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
final var velocityEngine = net.shibboleth.utilities.java.support.velocity.VelocityEngine.newVelocityEngine(props);
return velocityEngine;
} catch (final Exception e) {
throw new TechnicalException("Error configuring velocity", e);
}
}
use of org.pac4j.core.exception.TechnicalException in project pac4j by pac4j.
the class CasAuthenticator method validate.
@Override
public void validate(final Credentials cred, final WebContext context, final SessionStore sessionStore) {
init();
final var credentials = (TokenCredentials) cred;
final var ticket = credentials.getToken();
try {
final var finalCallbackUrl = callbackUrlResolver.compute(urlResolver, callbackUrl, clientName, context);
final var assertion = configuration.retrieveTicketValidator(context).validate(ticket, finalCallbackUrl);
final var principal = assertion.getPrincipal();
logger.debug("principal: {}", principal);
final var id = principal.getName();
final Map<String, Object> newPrincipalAttributes = new HashMap<>();
final Map<String, Object> newAuthenticationAttributes = new HashMap<>();
// restore both sets of attributes
final var oldPrincipalAttributes = principal.getAttributes();
final var oldAuthenticationAttributes = assertion.getAttributes();
if (oldPrincipalAttributes != null) {
oldPrincipalAttributes.entrySet().stream().forEach(e -> newPrincipalAttributes.put(e.getKey(), e.getValue()));
}
if (oldAuthenticationAttributes != null) {
oldAuthenticationAttributes.entrySet().stream().forEach(e -> newAuthenticationAttributes.put(e.getKey(), e.getValue()));
}
final var profile = getProfileDefinition().newProfile(id, configuration.getProxyReceptor(), principal);
profile.setId(ProfileHelper.sanitizeIdentifier(id));
getProfileDefinition().convertAndAdd(profile, newPrincipalAttributes, newAuthenticationAttributes);
logger.debug("profile returned by CAS: {}", profile);
credentials.setUserProfile(profile);
} catch (final TicketValidationException e) {
var message = "cannot validate CAS ticket: " + ticket;
throw new TechnicalException(message, e);
}
}
Aggregations