Search in sources :

Example 1 with AuthorityUtil

use of com.vmware.flowgate.util.AuthorityUtil in project flowgate by vmware.

the class AuthController method getPrivilegeName.

@RequestMapping(value = "/privileges", method = RequestMethod.GET)
public Set<String> getPrivilegeName(HttpServletRequest request) {
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    AuthorityUtil util = new AuthorityUtil();
    return util.getPrivilege(user);
}
Also used : WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) AuthorityUtil(com.vmware.flowgate.util.AuthorityUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AuthorityUtil

use of com.vmware.flowgate.util.AuthorityUtil in project flowgate by vmware.

the class AuthController method getToken.

@RequestMapping(value = "/token", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public AuthToken getToken(@RequestBody(required = false) WormholeUser user, @RequestHeader(name = "serviceKey", required = false) String serviceKey, HttpServletRequest request, HttpServletResponse response) {
    AuthToken access_token = null;
    if (user == null && serviceKey == null) {
        throw new WormholeRequestException(HttpStatus.UNAUTHORIZED, "Invalid username or password", null);
    }
    if (user != null) {
        access_token = accessTokenService.createToken(user);
    } else {
        if (InitializeConfigureData.checkServiceKey(serviceKey) || accessTokenService.validateServiceKey(serviceKey)) {
            List<String> roleNames = new ArrayList<String>();
            roleNames.add(FlowgateConstant.Role_admin);
            AuthorityUtil util = new AuthorityUtil();
            WormholeUserDetails userDetails = new WormholeUserDetails(FlowgateConstant.systemUser, FlowgateConstant.systemUser, FlowgateConstant.systemUser, util.createGrantedAuthorities(roleNames));
            access_token = jwtTokenUtil.generate(userDetails);
        } else {
            throw new WormholeRequestException(HttpStatus.UNAUTHORIZED, "Invalid username or password", null);
        }
    }
    Cookie cookie = new Cookie(JwtTokenUtil.Token_Name, access_token.getAccess_token());
    cookie.setHttpOnly(true);
    cookie.setPath("/");
    cookie.setDomain(request.getServerName());
    cookie.setMaxAge(expiration);
    response.addCookie(cookie);
    return access_token;
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) Cookie(javax.servlet.http.Cookie) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) AuthorityUtil(com.vmware.flowgate.util.AuthorityUtil) ArrayList(java.util.ArrayList) AuthToken(com.vmware.flowgate.common.model.AuthToken) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AuthorityUtil

use of com.vmware.flowgate.util.AuthorityUtil 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

AuthorityUtil (com.vmware.flowgate.util.AuthorityUtil)3 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)3 ArrayList (java.util.ArrayList)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AuthToken (com.vmware.flowgate.common.model.AuthToken)1 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)1 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)1 Cookie (javax.servlet.http.Cookie)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1