List of usage examples for org.springframework.security.core GrantedAuthority toString
public String toString()
From source file:net.shibboleth.idp.oidc.client.userinfo.authn.AuthenticationMethodRefAuthority.java
/** * Gets authentication class ref authority. * * @param authority the authority// ww w. jav a2s . c om * @return the authentication class ref authority */ public static AuthenticationMethodRefAuthority getAuthenticationClassRefAuthority( final GrantedAuthority authority) { final String typeAndRole = authority.toString(); if (typeAndRole.contains(AuthenticationMethodRefAuthority.class.getSimpleName())) { final String role = typeAndRole.split(",")[1]; return new AuthenticationMethodRefAuthority(role); } return null; }
From source file:net.shibboleth.idp.oidc.client.userinfo.authn.AuthenticationClassRefAuthority.java
/** * Gets authentication class ref authority. * * @param authority the authority// w ww .ja va2s.c o m * @return the authentication class ref authority */ public static AuthenticationClassRefAuthority getAuthenticationClassRefAuthority( final GrantedAuthority authority) { final String typeAndRole = authority.toString(); if (typeAndRole.contains(AuthenticationClassRefAuthority.class.getSimpleName())) { final String role = typeAndRole.split(",")[1]; return new AuthenticationClassRefAuthority(role); } return null; }
From source file:org.opendatakit.persistence.table.GrantedAuthorityHierarchyTable.java
public static final TreeMap<String, TreeSet<String>> getEntireGrantedAuthorityHierarchy(Datastore ds, User user) throws ODKDatastoreException { GrantedAuthorityHierarchyTable relation; List<? extends CommonFieldsBase> groupsList; relation = GrantedAuthorityHierarchyTable.assertRelation(ds, user); Query query = ds.createQuery(relation, "GrantedAuthorityHierarchyTable.getEntireGrantedAuthorityHierarchy", user);/*from w w w. j a v a 2 s . co m*/ query.addSort(GrantedAuthorityHierarchyTable.DOMINATING_GRANTED_AUTHORITY, Direction.ASCENDING); groupsList = query.executeQuery(); TreeMap<String, TreeSet<String>> inheritFrom = new TreeMap<String, TreeSet<String>>(); for (CommonFieldsBase b : groupsList) { GrantedAuthorityHierarchyTable group = (GrantedAuthorityHierarchyTable) b; GrantedAuthority dom = group.getDominatingGrantedAuthority(); GrantedAuthority sub = group.getSubordinateGrantedAuthority(); if (!GrantedAuthorityName.permissionsCanBeAssigned(dom.toString())) continue; TreeSet<String> auths = inheritFrom.get(dom.getAuthority()); if (auths == null) { auths = new TreeSet<String>(); inheritFrom.put(dom.getAuthority(), auths); } auths.add(sub.getAuthority()); } return inheritFrom; }
From source file:com.task.springsec.SecurityUtil.java
/** * /*from w w w . ja v a 2 s .co m*/ * @param authorities * @return */ private static Set<String> toRoles(Collection<? extends GrantedAuthority> authorities) { final Set<String> target = new HashSet<String>(); for (GrantedAuthority au : authorities) { if (null == au.getAuthority()) { throw new IllegalArgumentException( "Cannot process GrantedAuthority objects which return null from getAuthority() - attempting to process " + au.toString()); } target.add(au.getAuthority()); } return target; }
From source file:nc.noumea.mairie.annuairev2.saisie.core.security.SecurityUtil.java
/** * @param authorities/*from w ww . j a v a 2 s .co m*/ * @return */ private static Set<String> toRoles(Collection<? extends GrantedAuthority> authorities) { final Set<String> target = new HashSet<>(); for (GrantedAuthority au : authorities) { if (null == au.getAuthority()) { throw new IllegalArgumentException( "Cannot process GrantedAuthority objects which return null from getAuthority() - attempting to process " + au.toString()); } target.add(au.getAuthority()); } return target; }
From source file:org.zkoss.spring.security.SecurityUtil.java
private static Set authoritiesToRoles(Collection c) { final Set target = new HashSet(); for (Iterator iterator = c.iterator(); iterator.hasNext();) { GrantedAuthority authority = (GrantedAuthority) iterator.next(); if (null == authority.getAuthority()) { throw new IllegalArgumentException( "Cannot process GrantedAuthority objects which return null from getAuthority() - attempting to process " + authority.toString()); }// ww w. ja v a2s. co m target.add(authority.getAuthority()); } return target; }
From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java
/** * Check if the specified user is authorized to access the given data source. * * @param authentication user's authentication *//*from w w w .j a v a2s .c o m*/ public static boolean isUserAuthorized(Authentication authentication, JdbcOeDataSource ds) { Set<String> roles = ds.getRoles(); if (roles == null || roles.isEmpty()) { return true; } for (GrantedAuthority eachAuthority : authentication.getAuthorities()) { if (roles.contains(eachAuthority.toString())) { return true; } } return false; }
From source file:com.hillert.botanic.controller.AuthenticationController.java
@RequestMapping(value = "/authenticate", method = { RequestMethod.POST }) public AuthenticationToken authorize(@RequestBody AuthenticationRequest authenticationRequest, HttpServletRequest request) {//from w w w.j a v a2 s .co m UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( authenticationRequest.getUsername(), authenticationRequest.getPassword()); Authentication authentication = this.authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); HttpSession session = request.getSession(true); session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext()); UserDetails details = this.userDetailsService.loadUserByUsername(authenticationRequest.getUsername()); final Map<String, Boolean> roles = new HashMap<String, Boolean>(); for (GrantedAuthority authority : details.getAuthorities()) { roles.put(authority.toString(), Boolean.TRUE); } return new AuthenticationToken(details.getUsername(), roles, session.getId()); }
From source file:com.boxedfolder.carrot.web.client.security.UserXAuthTokenResource.java
@RequestMapping(value = "/client/authenticate", method = { RequestMethod.POST }) public UserTransfer authorize(@RequestParam String username, @RequestParam String password) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); Authentication authentication = authenticationManager.authenticate(token); SecurityContextHolder.getContext().setAuthentication(authentication); UserDetails details = userDetailsService.loadUserByUsername(username); Map<String, Boolean> roles = new HashMap<>(); for (GrantedAuthority authority : details.getAuthorities()) { roles.put(authority.toString(), Boolean.TRUE); }/*from w w w .ja v a 2s. c o m*/ return new UserTransfer(details.getUsername(), roles, tokenUtils.createToken(details)); }
From source file:org.openwms.client.security.AuthenticationController.java
/** * Try to authenticate credentials and set an authentication token. * /*w w w . j av a2s. c o m*/ * <ul> * <li>URL: {@value AuthenticationController#DO_LOGIN}.</li> * <li>Method: {@link RequestMethod.POST}</li> * </ul> * * @param authResource * The credentials to authenticate with * @return The authenticated resource */ @RequestMapping(value = DO_LOGIN, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE, headers = "Content-Type=application/json") @ResponseBody public AuthResource login(@RequestBody AuthResource authResource) { UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken( authResource.getUsername(), authResource.getPassword()); Authentication authentication = this.authenticationManager.authenticate(authenticationToken); SecurityContextHolder.getContext().setAuthentication(authentication); UserDetails userDetails = detailsService.loadUserByUsername(authResource.getUsername()); List<String> roles = new ArrayList<String>(); for (GrantedAuthority authority : userDetails.getAuthorities()) { roles.add(authority.toString()); } authResource.setGrants(roles); authResource.resetPassword(); authResource.setToken(TokenUtils.createToken(userDetails)); return authResource; }