Example usage for org.springframework.security.core Authentication getAuthorities

List of usage examples for org.springframework.security.core Authentication getAuthorities

Introduction

In this page you can find the example usage for org.springframework.security.core Authentication getAuthorities.

Prototype

Collection<? extends GrantedAuthority> getAuthorities();

Source Link

Document

Set by an AuthenticationManager to indicate the authorities that the principal has been granted.

Usage

From source file:com.devicehive.auth.rest.providers.HiveAnonymousAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    return new HiveAuthentication(new HivePrincipal(), authentication.getAuthorities());
}

From source file:SpringSecurity.AuthenticationHandler.java

protected String determineTargetUrl(Authentication authentication) {
    Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
    for (GrantedAuthority grantedAuthority : authorities) {
        if (grantedAuthority.getAuthority().equals("ROLE_USER")) {
            return "/student.html";
        } else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) {
            return "/admin.html";
        }//from   w w w  .ja va2  s. co m
    }
    return "/login.html";
}

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("/");
    }/*w w w . j a v a2s .co  m*/
}

From source file:com.olegchir.wicket_spring_security_example.init.UserAuthenticatedWebSession.java

@Override
public Roles getRoles() {
    Roles roles = new Roles();
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    for (GrantedAuthority authority : authentication.getAuthorities()) {
        roles.add(authority.getAuthority());
    }//from   ww w .j a  v  a2s.  co m
    return roles;
}

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  w  w  w. j  a  va 2  s.c o m*/
    if (roles.contains("ROLE_ADMIN")) {
        hsr1.sendRedirect(hsr.getContextPath() + "/admin/");
    }
}

From source file:com.epam.ta.reportportal.ws.resolver.ActiveUserWebArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer paramModelAndViewContainer,
        NativeWebRequest webRequest, WebDataBinderFactory paramWebDataBinderFactory) throws Exception {
    Authentication authentication = (Authentication) webRequest.getUserPrincipal();
    if (!authentication.getAuthorities().isEmpty()) {
        Optional<UserRole> userRole = UserRole
                .findByAuthority(authentication.getAuthorities().iterator().next().getAuthority());
        return userRole.isPresent() ? userRole.get() : WebArgumentResolver.UNRESOLVED;
    }/*from w w w  . j a  v a2 s . c o  m*/
    return WebArgumentResolver.UNRESOLVED;
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.security.SpringAuthenticatedWebSession.java

private void addRolesFromAuthentication(Roles roles, Authentication authentication) {
    for (GrantedAuthority authority : authentication.getAuthorities()) {
        roles.add(authority.getAuthority());
    }//from   ww  w.j  a  v  a 2s .  c  om
}

From source file:de.qucosa.urn.RoleBasedUrnConfiguration.java

@Bean
@Scope("request")
public URNConfiguration urnConfiguration(Authentication authentication,
        URNConfigurationMap urnConfigurationMap) {
    GrantedAuthority firstGranted = authentication.getAuthorities().iterator().next();
    String role = firstGranted.getAuthority();
    if (urnConfigurationMap.hasConfigurationFor(role)) {
        return urnConfigurationMap.get(role);
    } else {/* www .j a  v  a2 s . c om*/
        log.warn(
                "No URN configuration for authenticated role '{}' found. URN creation will not work for this request!",
                role);
    }
    return null;
}

From source file:at.ac.univie.isc.asio.security.SpringSecurityAuthorizer.java

@Override
public void check(final Invocation invocation) throws RuntimeException {
    final Permission required = invocation.requires();
    final Authentication authentication = fetchAndValidateAuthentication();
    for (final GrantedAuthority granted : authentication.getAuthorities()) {
        if (required.name().equals(granted.getAuthority())) {
            return;
        }/* ww w .  j ava  2 s  .  c o  m*/
    }
    log.debug("not authorized to invoke - required {} - granted {}", required, authentication.getAuthorities());
    throw new AccessDeniedException(Pretty.format("requires %s rights", required));
}

From source file:com.hp.autonomy.frontend.configuration.authentication.LoginSuccessHandler.java

@Override
protected String determineTargetUrl(final HttpServletRequest request, final HttpServletResponse response) {
    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    for (final GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
        if (roleDefault.equalsIgnoreCase(grantedAuthority.getAuthority())) {
            return configUrl;
        }/*  w  w w  . ja  va2 s .  c  om*/
    }

    return applicationUrl;
}