Search in sources :

Example 1 with ChainContext

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;
}
Also used : AuditLogEventFactory(org.simbasecurity.core.audit.AuditLogEventFactory) CONTINUE(org.simbasecurity.core.chain.Command.State.CONTINUE) FINISH(org.simbasecurity.core.chain.Command.State.FINISH) Autowired(org.springframework.beans.factory.annotation.Autowired) ChainContext(org.simbasecurity.core.chain.ChainContext) UserTokenService(org.simbasecurity.core.service.communication.token.UserTokenService) EmailFactory(org.simbasecurity.core.domain.user.EmailFactory) User(org.simbasecurity.core.domain.User) Component(org.springframework.stereotype.Component) Command(org.simbasecurity.core.chain.Command) CredentialService(org.simbasecurity.core.service.CredentialService) Audit(org.simbasecurity.core.audit.Audit) AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Optional(java.util.Optional) Token(org.simbasecurity.core.domain.communication.token.Token) AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) User(org.simbasecurity.core.domain.User)

Example 2 with ChainContext

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();
    });
}
Also used : ChainContext(org.simbasecurity.core.chain.ChainContext) Command(org.simbasecurity.core.chain.Command) TException(org.apache.thrift.TException) Session(org.simbasecurity.core.domain.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ChainContext (org.simbasecurity.core.chain.ChainContext)2 Command (org.simbasecurity.core.chain.Command)2 Optional (java.util.Optional)1 TException (org.apache.thrift.TException)1 Audit (org.simbasecurity.core.audit.Audit)1 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)1 AuditLogEventFactory (org.simbasecurity.core.audit.AuditLogEventFactory)1 CONTINUE (org.simbasecurity.core.chain.Command.State.CONTINUE)1 FINISH (org.simbasecurity.core.chain.Command.State.FINISH)1 Session (org.simbasecurity.core.domain.Session)1 User (org.simbasecurity.core.domain.User)1 Token (org.simbasecurity.core.domain.communication.token.Token)1 EmailFactory (org.simbasecurity.core.domain.user.EmailFactory)1 CredentialService (org.simbasecurity.core.service.CredentialService)1 UserTokenService (org.simbasecurity.core.service.communication.token.UserTokenService)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Component (org.springframework.stereotype.Component)1 Transactional (org.springframework.transaction.annotation.Transactional)1