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);
}
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;
}
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);
}
Aggregations