use of org.simbasecurity.core.chain.ChainContext in project simba-os by cegeka.
the class CheckTokenCommand method execute.
@Override
public State execute(ChainContext context) throws Exception {
Optional<User> userFromToken = context.getToken().map(Token::fromString).flatMap(token -> userTokenService.getUserForToken(token));
Optional<User> userFromEmail = context.getEmail().map(s -> emailFactory.email(s)).flatMap(email -> credentialService.findUserByMail(email));
if (noExistingUserForEmail(context, userFromEmail))
return FINISH;
if (noExistingUserForToken(context, userFromEmail.get(), userFromToken))
return FINISH;
if (existingUsersDoNotMatch(context, userFromEmail.get(), userFromToken.get()))
return FINISH;
User user = userFromToken.get();
context.setUserName(user.getUserName());
AuditLogEvent event = auditLogEventFactory.createEventForUserAuthentication(user.getUserName(), String.format("There was a successful reset password attempt for email address %s.", user.getEmail().asString()));
audit.log(event);
return CONTINUE;
}
use of org.simbasecurity.core.chain.ChainContext in project simba-os by cegeka.
the class AuthenticationFilterServiceImpl method processRequest.
@Transactional
public ActionDescriptor processRequest(RequestData requestData, String chainCommand) throws TException {
return simbaExceptionHandlingCaller.call(() -> {
if (requestData == null) {
throw new IllegalArgumentException("Parameter 'requestData' can not be null");
}
if (chainCommand == null) {
throw new IllegalArgumentException("Parameter 'chainCommand' can not be null");
}
Command chain = locateCommandChain(chainCommand);
Session currentSession = getCurrentSession(requestData);
ChainContext chainContext = createChainContext(requestData, currentSession);
try {
chain.execute(chainContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
return chainContext.getActionDescriptor();
});
}
Aggregations