use of org.apache.syncope.common.lib.oidc.OIDCRequest in project syncope by apache.
the class OIDCC4UILogic method createLoginRequest.
@PreAuthorize("hasRole('" + IdRepoEntitlement.ANONYMOUS + "')")
public OIDCRequest createLoginRequest(final String redirectURI, final String opName) {
// 1. look for OidcClient
OidcClient oidcClient = getOidcClient(opName, redirectURI);
oidcClient.setCallbackUrl(redirectURI);
// 2. create OIDCRequest
WithLocationAction action = oidcClient.getRedirectionAction(new OIDC4UIContext(), NoOpSessionStore.INSTANCE).map(WithLocationAction.class::cast).orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
sce.getElements().add("No RedirectionAction generated for LoginRequest");
return sce;
});
OIDCRequest loginRequest = new OIDCRequest();
loginRequest.setLocation(action.getLocation());
return loginRequest;
}
use of org.apache.syncope.common.lib.oidc.OIDCRequest in project syncope by apache.
the class BeforeLogoutResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
String postLogoutRedirectURI = StringUtils.substringBefore(request.getRequestURL().toString(), "/before-logout") + "/logout";
OIDCC4UIService service = BaseSession.class.cast(Session.get()).getService(OIDCC4UIService.class);
OIDCRequest logoutRequest = service.createLogoutRequest(postLogoutRedirectURI);
ResourceResponse response = new ResourceResponse();
response.setStatusCode(Response.Status.FOUND.getStatusCode());
response.getHeaders().addHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store");
response.getHeaders().addHeader("Pragma", "no-cache");
response.getHeaders().addHeader(HttpHeaders.LOCATION, logoutRequest.getLocation());
Session.get().invalidate();
return response;
}
use of org.apache.syncope.common.lib.oidc.OIDCRequest in project syncope by apache.
the class LoginResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
String op = attributes.getRequest().getQueryParameters().getParameterValue(OIDCC4UIConstants.PARAM_OP).toString();
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
String redirectURI = StringUtils.substringBefore(request.getRequestURL().toString(), "/login") + "/code-consumer";
OIDCC4UIService service = BaseSession.class.cast(Session.get()).getAnonymousService(OIDCC4UIService.class);
OIDCRequest loginRequest = service.createLoginRequest(redirectURI, op);
Session.get().setAttribute(OIDCConstants.OP, op);
ResourceResponse response = new ResourceResponse();
response.setStatusCode(Response.Status.FOUND.getStatusCode());
response.getHeaders().addHeader(HttpHeaders.CACHE_CONTROL, "no-cache, no-store");
response.getHeaders().addHeader("Pragma", "no-cache");
response.getHeaders().addHeader(HttpHeaders.LOCATION, loginRequest.getLocation());
return response;
}
use of org.apache.syncope.common.lib.oidc.OIDCRequest in project syncope by apache.
the class OIDCC4UILogic method createLogoutRequest.
@PreAuthorize("isAuthenticated() and not(hasRole('" + IdRepoEntitlement.ANONYMOUS + "'))")
public OIDCRequest createLogoutRequest(final String accessToken, final String redirectURI) {
// 0. fetch the current JWT used for Syncope authentication
JWTClaimsSet claimsSet;
try {
SignedJWT jwt = SignedJWT.parse(accessToken);
claimsSet = jwt.getJWTClaimsSet();
} catch (ParseException e) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAccessToken);
sce.getElements().add(e.getMessage());
throw sce;
}
// 1. look for OidcClient
OidcClient oidcClient = getOidcClient((String) claimsSet.getClaim(JWT_CLAIM_OP_NAME), redirectURI);
oidcClient.setCallbackUrl(redirectURI);
// 2. create OIDCRequest
OidcProfile profile = new OidcProfile();
profile.setIdTokenString((String) claimsSet.getClaim(JWT_CLAIM_ID_TOKEN));
WithLocationAction action = oidcClient.getLogoutAction(new OIDC4UIContext(), NoOpSessionStore.INSTANCE, profile, redirectURI).map(WithLocationAction.class::cast).orElseThrow(() -> {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
sce.getElements().add("No RedirectionAction generated for LogoutRequest");
return sce;
});
OIDCRequest logoutRequest = new OIDCRequest();
logoutRequest.setLocation(action.getLocation());
return logoutRequest;
}
Aggregations