use of org.apache.cxf.sts.token.canceller.TokenCancellerParameters in project cxf by apache.
the class EventMapper method handleEvent.
protected void handleEvent(TokenCancellerParametersSupport event, Map<String, Object> map) {
TokenCancellerParameters params = event.getTokenParameters();
HttpServletRequest req = (HttpServletRequest) params.getMessageContext().get(AbstractHTTPDestination.HTTP_REQUEST);
map.put(KEYS.REMOTE_HOST.name(), req.getRemoteHost());
map.put(KEYS.REMOTE_PORT.name(), String.valueOf(req.getRemotePort()));
map.put(KEYS.URL.name(), params.getMessageContext().get("org.apache.cxf.request.url"));
map.put(KEYS.TOKENTYPE.name(), params.getTokenRequirements().getTokenType());
if (params.getTokenRequirements().getActAs() != null) {
map.put(KEYS.CANCEL_PRINCIPAL.name(), params.getTokenRequirements().getCancelTarget().getPrincipal().getName());
}
if (params.getKeyRequirements() != null) {
map.put(KEYS.KEYTYPE.name(), params.getKeyRequirements().getKeyType());
}
if (params.getPrincipal() != null) {
map.put(KEYS.WS_SEC_PRINCIPAL.name(), params.getPrincipal().getName());
}
}
use of org.apache.cxf.sts.token.canceller.TokenCancellerParameters in project cxf by apache.
the class TokenCancelOperation method cancel.
public RequestSecurityTokenResponseType cancel(RequestSecurityTokenType request, Principal principal, Map<String, Object> messageContext) {
long start = System.currentTimeMillis();
TokenCancellerParameters cancellerParameters = new TokenCancellerParameters();
try {
RequestRequirements requestRequirements = parseRequest(request, messageContext);
KeyRequirements keyRequirements = requestRequirements.getKeyRequirements();
TokenRequirements tokenRequirements = requestRequirements.getTokenRequirements();
cancellerParameters.setStsProperties(stsProperties);
cancellerParameters.setPrincipal(principal);
cancellerParameters.setMessageContext(messageContext);
cancellerParameters.setTokenStore(getTokenStore());
cancellerParameters.setKeyRequirements(keyRequirements);
cancellerParameters.setTokenRequirements(tokenRequirements);
ReceivedToken cancelTarget = tokenRequirements.getCancelTarget();
if (cancelTarget == null || cancelTarget.getToken() == null) {
throw new STSException("No element presented for cancellation", STSException.INVALID_REQUEST);
}
cancellerParameters.setToken(cancelTarget);
if (tokenRequirements.getTokenType() == null) {
tokenRequirements.setTokenType(STSConstants.STATUS);
LOG.fine("Received TokenType is null, falling back to default token type: " + STSConstants.STATUS);
}
//
// Cancel token
//
TokenCancellerResponse tokenResponse = null;
for (TokenCanceller tokenCanceller : tokencancellers) {
if (tokenCanceller.canHandleToken(cancelTarget)) {
try {
tokenResponse = tokenCanceller.cancelToken(cancellerParameters);
} catch (RuntimeException ex) {
LOG.log(Level.WARNING, "", ex);
throw new STSException("Error while cancelling a token", ex, STSException.REQUEST_FAILED);
}
break;
}
}
if (tokenResponse == null || tokenResponse.getToken() == null) {
LOG.fine("No Token Canceller has been found that can handle this token");
throw new STSException("No token canceller found for requested token type: " + tokenRequirements.getTokenType(), STSException.REQUEST_FAILED);
}
if (tokenResponse.getToken().getState() != STATE.CANCELLED) {
LOG.log(Level.WARNING, "Token cancellation failed.");
throw new STSException("Token cancellation failed.");
}
// prepare response
try {
RequestSecurityTokenResponseType response = createResponse(tokenRequirements);
STSCancelSuccessEvent event = new STSCancelSuccessEvent(cancellerParameters, System.currentTimeMillis() - start);
publishEvent(event);
return response;
} catch (Throwable ex) {
LOG.log(Level.WARNING, "", ex);
throw new STSException("Error in creating the response", ex, STSException.REQUEST_FAILED);
}
} catch (RuntimeException ex) {
STSCancelFailureEvent event = new STSCancelFailureEvent(cancellerParameters, System.currentTimeMillis() - start, ex);
publishEvent(event);
throw ex;
}
}
Aggregations