Search in sources :

Example 31 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 32 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 33 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)

Example 34 with UserDetails

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

the class UserController method authenticate.

@RequestMapping(value = "/authenticate", method = RequestMethod.POST)
public TokenTransfer authenticate(@RequestParam("username") String username, @RequestParam("password") String password) {
    UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
    Authentication authentication = authManager.authenticate(authenticationToken);
    SecurityContextHolder.getContext().setAuthentication(authentication);
    UserDetails userDetails = userDetailsService.loadUserByUsername(username);
    return new TokenTransfer(TokenUtils.createToken(userDetails));
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) Authentication(org.springframework.security.core.Authentication) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) TokenTransfer(com.weibo.model.TokenTransfer) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with UserDetails

use of org.springframework.security.core.userdetails.UserDetails in project incubator-atlas by apache.

the class AtlasAbstractAuthenticationProvider method getAuthenticationWithGrantedAuthorityFromUGI.

public Authentication getAuthenticationWithGrantedAuthorityFromUGI(Authentication authentication) {
    UsernamePasswordAuthenticationToken result = null;
    if (authentication != null && authentication.isAuthenticated()) {
        List<GrantedAuthority> grantedAuthsUGI = getAuthoritiesFromUGI(authentication.getName());
        final UserDetails userDetails = new User(authentication.getName(), authentication.getCredentials().toString(), grantedAuthsUGI);
        result = new UsernamePasswordAuthenticationToken(userDetails, authentication.getCredentials(), grantedAuthsUGI);
        result.setDetails(authentication.getDetails());
        return result;
    }
    return authentication;
}
Also used : UserDetails(org.springframework.security.core.userdetails.UserDetails) User(org.springframework.security.core.userdetails.User) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken)

Aggregations

UserDetails (org.springframework.security.core.userdetails.UserDetails)111 Test (org.junit.Test)42 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)33 Authentication (org.springframework.security.core.Authentication)32 GrantedAuthority (org.springframework.security.core.GrantedAuthority)17 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)15 User (org.springframework.security.core.userdetails.User)14 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)10 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)9 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 LdapUserDetailsService (org.springframework.security.ldap.userdetails.LdapUserDetailsService)7 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)6 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Date (java.util.Date)4 User (org.apache.atlas.web.model.User)4 User (org.hisp.dhis.user.User)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 AuthenticationException (org.springframework.security.core.AuthenticationException)4