List of usage examples for org.springframework.security.core.authority AuthorityUtils authorityListToSet
public static Set<String> authorityListToSet(Collection<? extends GrantedAuthority> userAuthorities)
From source file:at.ac.univie.isc.asio.security.AuthInfo.java
/** * Derive authorization info from the given identity and role. * * @param login login name used by client * @param identity identity of authorized client * @param authorities all authorities granted to client * @return information on authorization// ww w . ja v a 2 s .c o m */ public static AuthInfo from(final String login, final Identity identity, final Collection<? extends GrantedAuthority> authorities) { final String name = identity.nameOrIfUndefined(null); final String secret = identity.isDefined() ? identity.getSecret() : null; return create(name, secret, login, AuthorityUtils.authorityListToSet(authorities)); }
From source file:com.opiframe.utils.AutehnticationHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication a) throws IOException, ServletException { Set<String> roles = AuthorityUtils.authorityListToSet(a.getAuthorities()); if (roles.contains("ROLE_USER")) { response.sendRedirect("/"); }/* www . j a v a2 s .c o m*/ }
From source file:cz.muni.pa165.carparkapp.configuration.AuthenticationHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest hsr, HttpServletResponse hsr1, Authentication a) throws IOException, ServletException { Set<String> roles = AuthorityUtils.authorityListToSet(a.getAuthorities()); if (roles.contains("ROLE_USER")) { hsr1.sendRedirect(hsr.getContextPath() + "/"); }//from ww w . jav a 2s. com if (roles.contains("ROLE_ADMIN")) { hsr1.sendRedirect(hsr.getContextPath() + "/admin/"); } }
From source file:hotel.web.util.HotelAuthenticationHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { String userTargetUrl = "/user/index.jsp"; // change "memmber" to whatever you use String adminTargetUrl = "/user/index.jsp"; // change "admin" to whatever you use and add more taretURLs if needed Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (roles.contains("ROLE_ADMIN")) { getRedirectStrategy().sendRedirect(request, response, adminTargetUrl); } else if (roles.contains("ROLE_USER")) { getRedirectStrategy().sendRedirect(request, response, userTargetUrl); } else {/* w w w . j a v a 2 s . co m*/ super.onAuthenticationSuccess(request, response, authentication); return; } }
From source file:hotel.web.util.MyAuthenticationHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { String userTargetUrl = "/user/index.jsp"; // change "memmber" to whatever you use String adminTargetUrl = "/admin/index.jsp"; // change "admin" to whatever you use and add more taretURLs if needed Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (roles.contains("ROLE_ADMIN")) { getRedirectStrategy().sendRedirect(request, response, adminTargetUrl); } else if (roles.contains("ROLE_USER")) { getRedirectStrategy().sendRedirect(request, response, userTargetUrl); } else {//www.jav a2s. c om super.onAuthenticationSuccess(request, response, authentication); return; } }
From source file:ph.fingra.statisticsweb.security.FingraphAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (roles.contains("ROLE_ADMIN")) { //getRedirectStrategy().sendRedirect(request, response, adminTargetUrl); setDefaultTargetUrl(adminTargetUrl); } else if (roles.contains("ROLE_USER")) { // getRedirectStrategy().sendRedirect(request, response, userTargetUrl); setDefaultTargetUrl(userTargetUrl); }//from ww w . j a v a 2 s . c o m super.onAuthenticationSuccess(request, response, authentication); return; }
From source file:org.meruvian.yama.webapi.config.oauth.UserTokenConverter.java
public Map<String, ?> convertUserAuthentication(Authentication authentication) { Map<String, Object> response = new LinkedHashMap<String, Object>(); response.put(USERNAME, authentication.getName()); if (authentication.getPrincipal() instanceof DefaultUserDetails) { DefaultUserDetails details = (DefaultUserDetails) authentication.getPrincipal(); response.put(USER_ID, details.getId()); }/* w ww. ja va2s. co m*/ if (authentication.getAuthorities() != null && !authentication.getAuthorities().isEmpty()) { response.put(AUTHORITIES, AuthorityUtils.authorityListToSet(authentication.getAuthorities())); } return response; }
From source file:org.cloudfoundry.identity.uaa.security.DefaultSecurityContextAccessor.java
@Override public boolean isAdmin() { Authentication a = SecurityContextHolder.getContext().getAuthentication(); return a != null && AuthorityUtils.authorityListToSet(a.getAuthorities()).contains("uaa.admin"); }
From source file:org.cloudfoundry.identity.uaa.scim.job.AdminUsersTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { String authorities = StringUtils.collectionToCommaDelimitedString( AuthorityUtils.authorityListToSet(authority == UaaAuthority.UAA_USER ? UaaAuthority.USER_AUTHORITIES : UaaAuthority.ADMIN_AUTHORITIES)); for (String user : admins) { int updated = jdbcTemplate.update("update users set authorities=? where userName=?", authorities, user); contribution.incrementWriteCount(updated); }//from w ww . j ava 2 s.c o m return RepeatStatus.FINISHED; }
From source file:com.cb.controllers.WebSocketsController.java
/** * Used for redirecting the login page based on User Roles * @return /* w w w. j a v a 2 s . c o m*/ */ @RequestMapping(value = "/welcome") protected View welcome() { Set<String> roles = AuthorityUtils .authorityListToSet(SecurityContextHolder.getContext().getAuthentication().getAuthorities()); if (roles.contains("ROLE_ADMIN")) { return new RedirectView("admin/list"); } if (roles.contains("ROLE_USER")) { return new RedirectView("user/patient/list"); } if (roles.contains("ROLE_DOC")) { return new RedirectView("doctor/list"); } return new RedirectView("home"); }