Java Code Examples for org.springframework.security.core.authority.AuthorityUtils#authorityListToSet()
The following examples show how to use
org.springframework.security.core.authority.AuthorityUtils#authorityListToSet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RoleWiseSuccessHandler.java From zhcet-web with Apache License 2.0 | 6 votes |
public static String determineTargetUrl(Authentication authentication) { Set<String> authorities = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (authorities.contains(Role.DEAN_ADMIN.toString())) return "/admin/dean"; else if (authorities.contains(Role.DEVELOPMENT_ADMIN.toString())) return "/actuator/health"; else if (authorities.contains(Role.DEPARTMENT_ADMIN.toString())) return "/admin/department"; else if (authorities.contains(Role.FACULTY.toString())) return "/admin/faculty/courses"; else if (authorities.contains(Role.STUDENT.toString())) return "/dashboard/student/attendance"; else if (authorities.contains(Role.USER.toString())) return "/profile"; else return "/login"; }
Example 2
Source File: CustomAuthenticationSuccessHandler.java From market with MIT License | 6 votes |
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (roles.contains("ROLE_USER")) { UserAccount account = userAccountService.findByEmail(authentication.getName()); CartDTO cartDto = prepareCartDto(account); request.getSession().setAttribute("cart", cartDto); } if (isStaff(roles)) { response.sendRedirect(servletContext.getContextPath() + "/admin/"); } else { response.sendRedirect(servletContext.getContextPath() + "/"); } request.getSession(false).setMaxInactiveInterval(30); }
Example 3
Source File: SecuredRateLimitUtils.java From spring-cloud-zuul-ratelimit with Apache License 2.0 | 5 votes |
@Override public Set<String> getUserRoles() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { return emptySet(); } return AuthorityUtils.authorityListToSet(authentication.getAuthorities()); }
Example 4
Source File: DefaultOAuth2RequestFactory.java From MaxKey with Apache License 2.0 | 5 votes |
private Set<String> checkUserScopes(Set<String> scopes, ClientDetails clientDetails) { if (!securityContextAccessor.isUser()) { return scopes; } Set<String> result = new LinkedHashSet<String>(); Set<String> authorities = AuthorityUtils.authorityListToSet(securityContextAccessor.getAuthorities()); for (String scope : scopes) { if (authorities.contains(scope) || authorities.contains(scope.toUpperCase()) || authorities.contains("ROLE_" + scope.toUpperCase())) { result.add(scope); } } return result; }
Example 5
Source File: MySecurityExpressionRoot.java From tutorials with MIT License | 5 votes |
private Set<String> getAuthoritySet() { if (roles == null) { roles = new HashSet<String>(); Collection<? extends GrantedAuthority> userAuthorities = authentication.getAuthorities(); if (roleHierarchy != null) { userAuthorities = roleHierarchy.getReachableGrantedAuthorities(userAuthorities); } roles = AuthorityUtils.authorityListToSet(userAuthorities); } return roles; }
Example 6
Source File: BaseClientDetails.java From MaxKey with Apache License 2.0 | 4 votes |
@com.fasterxml.jackson.annotation.JsonProperty("authorities") private List<String> getAuthoritiesAsStrings() { return new ArrayList<String>( AuthorityUtils.authorityListToSet(authorities)); }
Example 7
Source File: SubscriptionServiceImpl.java From OpenESPI-Common-java with Apache License 2.0 | 4 votes |
@Override @Transactional(rollbackFor = { javax.xml.bind.JAXBException.class }, noRollbackFor = { javax.persistence.NoResultException.class, org.springframework.dao.EmptyResultDataAccessException.class }) public Subscription createSubscription(OAuth2Authentication authentication) { Subscription subscription = new Subscription(); subscription.setUUID(UUID.randomUUID()); // Determine requestor's Role Set<String> role = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (role.contains("ROLE_USER")) { subscription.setApplicationInformation(applicationInformationService .findByClientId(authentication.getOAuth2Request().getClientId())); subscription.setRetailCustomer((RetailCustomer) authentication.getPrincipal()); subscription.setUsagePoints(new ArrayList<UsagePoint>()); // set up the subscription's usagePoints list. Keep in mind that right // now this is ALL usage points belonging to the RetailCustomer. // TODO - scope this to only a selected (proper) subset of the // usagePoints as passed // through from the UX or a restful call. List<Long> upIds = resourceService.findAllIdsByXPath(subscription .getRetailCustomer().getId(), UsagePoint.class); Iterator<Long> it = upIds.iterator(); while (it.hasNext()) { UsagePoint usagePoint = resourceService.findById(it.next(), UsagePoint.class); subscription.getUsagePoints().add(usagePoint); } } else { String clientId = authentication.getOAuth2Request().getClientId(); String ci = clientId; if (ci.indexOf("REGISTRATION_") != -1) { if (ci.substring(0, "REGISTRATION_".length()).equals( "REGISTRATION_")) { ci = ci.substring("REGISTRATION_".length()); } } if (ci.indexOf("_admin") != -1) { ci = ci.substring(0, ci.indexOf("_admin")); } subscription.setApplicationInformation(applicationInformationService.findByClientId(ci)); subscription.setRetailCustomer(retailCustomerService.findById((long) 0)); } subscription.setLastUpdate(new GregorianCalendar()); subscriptionRepository.persist(subscription); return subscription; }