Search in sources :

Example 56 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project midpoint by Evolveum.

the class MidPointAbstractAuthenticationProvider method supports.

public boolean supports(Class<?> authenticationClass, Authentication authentication) {
    if (!(authentication instanceof MidpointAuthentication)) {
        return supports(authenticationClass);
    }
    MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
    ModuleAuthentication moduleAuthentication = getProcessingModule(mpAuthentication);
    if (moduleAuthentication == null || moduleAuthentication.getAuthentication() == null) {
        return false;
    }
    if (moduleAuthentication.getAuthentication() instanceof AnonymousAuthenticationToken) {
        // hack for specific situation when user is anonymous, but accessDecisionManager resolve it
        return true;
    }
    return supports(moduleAuthentication.getAuthentication().getClass());
}
Also used : ModuleAuthentication(com.evolveum.midpoint.authentication.api.config.ModuleAuthentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 57 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project midpoint by Evolveum.

the class MidpointAnonymousAuthenticationFilter method createBasicAuthentication.

protected Authentication createBasicAuthentication(HttpServletRequest request) {
    AnonymousAuthenticationToken auth = new AnonymousAuthenticationToken(key, getPrincipal(), getAuthorities());
    auth.setDetails(authenticationDetailsSource.buildDetails(request));
    return auth;
}
Also used : AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 58 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project midpoint by Evolveum.

the class MidpointExceptionTranslationFilter method sendStartAuthentication.

@Override
protected void sendStartAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, AuthenticationException reason) throws ServletException, IOException {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (!AuthSequenceUtil.isRecordSessionLessAccessChannel(request)) {
        requestCache.saveRequest(request, response);
    }
    LOGGER.debug("Calling Authentication entry point.");
    getAuthenticationEntryPoint().commence(request, response, reason);
    if (authentication instanceof MidpointAuthentication) {
        MidpointAuthentication mpAuthentication = (MidpointAuthentication) authentication;
        ModuleAuthenticationImpl moduleAuthentication = (ModuleAuthenticationImpl) mpAuthentication.getProcessingModuleAuthentication();
        if (moduleAuthentication != null && moduleAuthentication.getAuthentication() instanceof AnonymousAuthenticationToken) {
            moduleAuthentication.setAuthentication(createNewAuthentication((AnonymousAuthenticationToken) moduleAuthentication.getAuthentication()));
            mpAuthentication.setPrincipal(null);
        }
        SecurityContextHolder.getContext().setAuthentication(mpAuthentication);
    }
}
Also used : ModuleAuthenticationImpl(com.evolveum.midpoint.authentication.impl.module.authentication.ModuleAuthenticationImpl) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication) Authentication(org.springframework.security.core.Authentication) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) MidpointAuthentication(com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)

Example 59 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project cia by Hack23.

the class AbstractServiceFunctionalIntegrationTest method setAuthenticatedAdminuser.

/**
 * Sets the authenticated adminuser.
 */
protected final void setAuthenticatedAdminuser() {
    final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(ROLE_ADMIN));
    authorities.add(new SimpleGrantedAuthority(ROLE_ANONYMOUS));
    SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(KEY, PRINCIPAL, authorities));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ArrayList(java.util.ArrayList) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Example 60 with AnonymousAuthenticationToken

use of org.springframework.security.authentication.AnonymousAuthenticationToken in project cia by Hack23.

the class AbstractServiceFunctionalIntegrationTest method setAuthenticatedAnonymousUser.

/**
 * Sets the authenticated anonymous user.
 */
protected final void setAuthenticatedAnonymousUser() {
    final Collection<SimpleGrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority(ROLE_ANONYMOUS));
    SecurityContextHolder.getContext().setAuthentication(new AnonymousAuthenticationToken(KEY, PRINCIPAL, authorities));
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ArrayList(java.util.ArrayList) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken)

Aggregations

AnonymousAuthenticationToken (org.springframework.security.authentication.AnonymousAuthenticationToken)87 Authentication (org.springframework.security.core.Authentication)37 Test (org.junit.jupiter.api.Test)22 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)17 ArrayList (java.util.ArrayList)14 GrantedAuthority (org.springframework.security.core.GrantedAuthority)13 SecurityContext (org.springframework.security.core.context.SecurityContext)10 MidpointAuthentication (com.evolveum.midpoint.authentication.api.config.MidpointAuthentication)8 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)7 ModuleAuthentication (com.evolveum.midpoint.authentication.api.config.ModuleAuthentication)6 Before (org.junit.Before)5 Test (org.junit.Test)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 PreAuthenticatedAuthenticationToken (org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 FilterChain (jakarta.servlet.FilterChain)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3