Search in sources :

Example 26 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project spring-security by spring-projects.

the class AbstractLdapAuthenticationProvider method authenticate.

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, this.messages.getMessage("LdapAuthenticationProvider.onlySupports", "Only UsernamePasswordAuthenticationToken is supported"));
    final UsernamePasswordAuthenticationToken userToken = (UsernamePasswordAuthenticationToken) authentication;
    String username = userToken.getName();
    String password = (String) authentication.getCredentials();
    if (this.logger.isDebugEnabled()) {
        this.logger.debug("Processing authentication request for user: " + username);
    }
    if (!StringUtils.hasLength(username)) {
        throw new BadCredentialsException(this.messages.getMessage("LdapAuthenticationProvider.emptyUsername", "Empty Username"));
    }
    if (!StringUtils.hasLength(password)) {
        throw new BadCredentialsException(this.messages.getMessage("AbstractLdapAuthenticationProvider.emptyPassword", "Empty Password"));
    }
    Assert.notNull(password, "Null password was supplied in authentication token");
    DirContextOperations userData = doAuthentication(userToken);
    UserDetails user = this.userDetailsContextMapper.mapUserFromContext(userData, authentication.getName(), loadUserAuthorities(userData, authentication.getName(), (String) authentication.getCredentials()));
    return createSuccessfulAuthentication(userToken, user);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) DirContextOperations(org.springframework.ldap.core.DirContextOperations) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 27 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.

the class UserPermissionInterceptor method handleRequest.

public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = null;
    if (principal instanceof UserDetails) {
        username = ((UserDetails) principal).getUsername();
    } else {
        username = principal.toString();
    }
    UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
    UserAccountBean userAccountBean = ((UserAccountBean) userAccountDao.findByUserName(username));
    Boolean result = userAccountBean.getRunWebservices();
    if (!result) {
        SoapBody response = ((SoapMessage) messageContext.getResponse()).getSoapBody();
        response.addClientOrSenderFault("Authorization is required to execute SOAP web services with this account.Please contact your administrator.", Locale.ENGLISH);
        return false;
    } else {
        return result;
    }
}
Also used : Locale(java.util.Locale) UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SoapBody(org.springframework.ws.soap.SoapBody) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) SoapMessage(org.springframework.ws.soap.SoapMessage)

Example 28 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.

the class StudySubjectEndpoint method getUserAccount.

/**
     * Helper Method to get the user account
     * 
     * @return UserAccountBean
     */
private UserAccountBean getUserAccount() {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = null;
    if (principal instanceof UserDetails) {
        username = ((UserDetails) principal).getUsername();
    } else {
        username = principal.toString();
    }
    UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
    return (UserAccountBean) userAccountDao.findByUserName(username);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 29 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.

the class DataEndpoint method getUserAccount.

/**
     * Helper Method to get the user account
     * 
     * @return UserAccountBean
     */
private UserAccountBean getUserAccount() {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = null;
    if (principal instanceof UserDetails) {
        username = ((UserDetails) principal).getUsername();
    } else {
        username = principal.toString();
    }
    UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
    return (UserAccountBean) userAccountDao.findByUserName(username);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 30 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project OpenClinica by OpenClinica.

the class EventEndpoint method getUserAccount.

/**
     * Helper Method to get the user account
     * 
     * @return UserAccountBean
     */
private UserAccountBean getUserAccount() {
    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    String username = null;
    if (principal instanceof UserDetails) {
        username = ((UserDetails) principal).getUsername();
    } else {
        username = principal.toString();
    }
    UserAccountDAO userAccountDao = new UserAccountDAO(dataSource);
    return (UserAccountBean) userAccountDao.findByUserName(username);
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Aggregations

UserDetails (org.springframework.security.core.userdetails.UserDetails)97 Test (org.junit.Test)37 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)32 Authentication (org.springframework.security.core.Authentication)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)16 User (org.springframework.security.core.userdetails.User)14 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)14 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)9 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)8 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)6 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)6 User (org.apache.atlas.web.model.User)4 User (org.hisp.dhis.user.User)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 DirContextAdapter (org.springframework.ldap.core.DirContextAdapter)3