Search in sources :

Example 26 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class AccessTokenService method refreshToken.

public AuthToken refreshToken(String token) {
    DecodedJWT jwt = jwtTokenUtil.getDecodedJwt(token);
    WormholeUser user = userservice.getUserByName(jwt.getSubject());
    ObjectMapper mapper = new ObjectMapper();
    if (jwtTokenUtil.isCreatedAfterLastPasswordReset(jwt.getIssuedAt(), user.getLastPasswordResetDate())) {
        String userdetailString = getUserJsonString(token);
        WormholeUserDetails userDetails = null;
        try {
            userDetails = mapper.readValue(userdetailString, WormholeUserDetails.class);
        } catch (IOException e) {
            logger.error(e.getMessage());
            return null;
        }
        AuthToken refreshToken = jwtTokenUtil.generate(userDetails);
        redisTemplate.delete(JwtTokenUtil.Prefix_token + token);
        return refreshToken;
    }
    return null;
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) AuthToken(com.vmware.flowgate.common.model.AuthToken) IOException(java.io.IOException) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WormholeUser(com.vmware.flowgate.common.model.WormholeUser)

Example 27 with WormholeUser

use of com.vmware.flowgate.common.model.WormholeUser in project flowgate by vmware.

the class UserDetailsServiceImpl method loadUserByUsername.

@Override
public WormholeUserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
    WormholeUser user = getUserByName(userName);
    AuthorityUtil authorityUtil = new AuthorityUtil();
    List<GrantedAuthority> privileges = new ArrayList<GrantedAuthority>();
    if (user == null) {
        throw new UsernameNotFoundException(String.format("No user found with username '%s'.", userName));
    }
    privileges = authorityUtil.createGrantedAuthorities(user.getRoleNames());
    return new WormholeUserDetails(user.getId(), user.getUserName(), user.getPassword(), privileges);
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) AuthorityUtil(com.vmware.flowgate.util.AuthorityUtil) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) WormholeUser(com.vmware.flowgate.common.model.WormholeUser)

Aggregations

WormholeUser (com.vmware.flowgate.common.model.WormholeUser)27 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)18 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 ArrayList (java.util.ArrayList)14 MvcResult (org.springframework.test.web.servlet.MvcResult)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)3 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Date (java.util.Date)2 Optional (java.util.Optional)2 PageRequest (org.springframework.data.domain.PageRequest)2 AuthToken (com.vmware.flowgate.common.model.AuthToken)1 SoftwareType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType)1 AuthorityUtil (com.vmware.flowgate.util.AuthorityUtil)1 IOException (java.io.IOException)1 Cookie (javax.servlet.http.Cookie)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1