Search in sources :

Example 1 with AuthenticationFailedException

use of org.apache.ftpserver.ftplet.AuthenticationFailedException in project structr by structr.

the class StructrUserManager method authenticate.

@Override
public User authenticate(Authentication auth) throws AuthenticationFailedException {
    logger.debug("Authentication: {}", auth);
    String userName = null;
    String password = null;
    if (auth instanceof UsernamePasswordAuthentication) {
        org.structr.web.entity.User user = null;
        // Use superuser context for authentication only
        try (Tx tx = StructrApp.getInstance().tx()) {
            UsernamePasswordAuthentication authentication = (UsernamePasswordAuthentication) auth;
            userName = authentication.getUsername();
            password = authentication.getPassword();
            user = (org.structr.web.entity.User) AuthHelper.getPrincipalForPassword(Principal.name, userName, password);
            securityContext = SecurityContext.getInstance(user, AccessMode.Backend);
            tx.success();
        } catch (FrameworkException ex) {
            logger.warn("FTP authentication attempt failed with username {} and password {}", new Object[] { userName, password });
        }
        if (user != null) {
            return new StructrFtpUser(securityContext, user);
        }
    }
    throw new AuthenticationFailedException("No structr user found for credentials " + userName + "/" + password);
}
Also used : Tx(org.structr.core.graph.Tx) FrameworkException(org.structr.common.error.FrameworkException) AuthenticationFailedException(org.apache.ftpserver.ftplet.AuthenticationFailedException) UsernamePasswordAuthentication(org.apache.ftpserver.usermanager.UsernamePasswordAuthentication)

Example 2 with AuthenticationFailedException

use of org.apache.ftpserver.ftplet.AuthenticationFailedException in project ddf by codice.

the class UserManagerImpl method authenticate.

/**
     * @param authentication The {@link Authentication} that proves the users identity. {@link org.apache.ftpserver.usermanager.AnonymousAuthentication} is not permitted
     * @return {@link User} upon successful authorization
     * @throws AuthenticationFailedException upon unsuccessful authorization
     */
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
    UPAuthenticationToken upAuthenticationToken;
    String username;
    User user;
    if (authentication instanceof UsernamePasswordAuthentication) {
        username = ((UsernamePasswordAuthentication) authentication).getUsername();
        upAuthenticationToken = new UPAuthenticationToken(username, ((UsernamePasswordAuthentication) authentication).getPassword());
        try {
            Subject subject = securityManager.getSubject(upAuthenticationToken);
            if (subject != null) {
                if (!doesExist(username)) {
                    user = createUser(username, subject);
                } else {
                    user = getUserByName(username);
                    updateUserSubject(user, subject);
                }
                return user;
            }
        } catch (SecurityServiceException e) {
            LOGGER.info("Failure to retrieve subject.", e);
            throw new AuthenticationFailedException("Failure to retrieve subject.");
        }
    }
    throw new AuthenticationFailedException("Authentication failed");
}
Also used : SecurityServiceException(ddf.security.service.SecurityServiceException) FtpUser(ddf.catalog.ftp.user.FtpUser) User(org.apache.ftpserver.ftplet.User) AuthenticationFailedException(org.apache.ftpserver.ftplet.AuthenticationFailedException) UPAuthenticationToken(org.codice.ddf.security.handler.api.UPAuthenticationToken) UsernamePasswordAuthentication(org.apache.ftpserver.usermanager.UsernamePasswordAuthentication) Subject(ddf.security.Subject)

Aggregations

AuthenticationFailedException (org.apache.ftpserver.ftplet.AuthenticationFailedException)2 UsernamePasswordAuthentication (org.apache.ftpserver.usermanager.UsernamePasswordAuthentication)2 FtpUser (ddf.catalog.ftp.user.FtpUser)1 Subject (ddf.security.Subject)1 SecurityServiceException (ddf.security.service.SecurityServiceException)1 User (org.apache.ftpserver.ftplet.User)1 UPAuthenticationToken (org.codice.ddf.security.handler.api.UPAuthenticationToken)1 FrameworkException (org.structr.common.error.FrameworkException)1 Tx (org.structr.core.graph.Tx)1