Search in sources :

Example 6 with AuthToken

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

the class AuthControllerTest method testRefreshToken1.

@Test
public void testRefreshToken1() throws Exception {
    AuthToken token = new AuthToken();
    Mockito.doReturn(token).when(tokenService).refreshToken(any());
    this.mockMvc.perform(get("/v1/auth/token/refresh")).andExpect(status().isOk()).andReturn();
}
Also used : AuthToken(com.vmware.flowgate.common.model.AuthToken) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with AuthToken

use of com.vmware.flowgate.common.model.AuthToken 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)

Aggregations

AuthToken (com.vmware.flowgate.common.model.AuthToken)7 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)3 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)3 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Cookie (javax.servlet.http.Cookie)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Algorithm (com.auth0.jwt.algorithms.Algorithm)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)1 AuthorityUtil (com.vmware.flowgate.util.AuthorityUtil)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 Authentication (org.springframework.security.core.Authentication)1