use of org.pac4j.core.exception.TechnicalException in project ratpack by ratpack.
the class RatpackPac4j method initiateAuthentication.
private static void initiateAuthentication(Context ctx, Class<? extends Client<?, ?>> clientType) {
Request request = ctx.getRequest();
Clients clients = ctx.get(Clients.class);
Client<?, ?> client = clients.findClient(clientType);
RatpackWebContext.from(ctx, false).then(webContext -> {
webContext.getSession().set(Pac4jSessionKeys.REQUESTED_URL, request.getUri());
try {
client.redirect(webContext, true);
} catch (Exception e) {
if (e instanceof RequiresHttpAction) {
webContext.sendResponse((RequiresHttpAction) e);
return;
} else {
ctx.error(new TechnicalException("Failed to redirect", e));
}
}
webContext.sendResponse();
});
}
use of org.pac4j.core.exception.TechnicalException in project knox by apache.
the class KnoxSessionStore method set.
public void set(WebContext context, String key, Object value) {
logger.debug("Save in session: {} = {}", key, value);
final Cookie cookie = new Cookie(PAC4J_SESSION_PREFIX + key, compressEncryptBase64(value));
try {
String domain = Urls.getDomainName(context.getFullRequestURL(), this.domainSuffix);
if (domain == null) {
domain = context.getServerName();
}
cookie.setDomain(domain);
} catch (final Exception e) {
throw new TechnicalException(e);
}
cookie.setHttpOnly(true);
cookie.setSecure(ContextHelper.isHttpsOrSecure(context));
context.addResponseCookie(cookie);
}
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 SignedJWT 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 SecretSignatureConfiguration method sign.
@Override
public SignedJWT sign(final JWTClaimsSet claims) {
init();
try {
final JWSSigner signer = new MACSigner(this.secret);
final SignedJWT 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 JwtAuthenticator method createJwtProfile.
@SuppressWarnings("unchecked")
protected void createJwtProfile(final TokenCredentials credentials, final JWT jwt) throws ParseException {
final JWTClaimsSet claimSet = jwt.getJWTClaimsSet();
String subject = claimSet.getSubject();
if (subject == null) {
throw new TechnicalException("JWT must contain a subject ('sub' claim)");
}
final Date expirationTime = claimSet.getExpirationTime();
if (expirationTime != null) {
final Date now = new Date();
if (expirationTime.before(now)) {
logger.error("The JWT is expired: no profile is built");
return;
}
}
final Map<String, Object> attributes = new HashMap<>(claimSet.getClaims());
attributes.remove(JwtClaims.SUBJECT);
final List<String> roles = (List<String>) attributes.get(JwtGenerator.INTERNAL_ROLES);
attributes.remove(JwtGenerator.INTERNAL_ROLES);
final List<String> permissions = (List<String>) attributes.get(JwtGenerator.INTERNAL_PERMISSIONS);
attributes.remove(JwtGenerator.INTERNAL_PERMISSIONS);
final CommonProfile profile = ProfileHelper.restoreOrBuildProfile(getProfileDefinition(), subject, attributes, null);
if (roles != null) {
profile.addRoles(roles);
}
if (permissions != null) {
profile.addPermissions(permissions);
}
credentials.setUserProfile(profile);
}
Aggregations