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

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

Introduction

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

Prototype

void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;

Source Link

Document

See #isAuthenticated() for a full description.

Usage

From source file:se.kth.csc.config.MockAuthConfig.java

@Bean
@Autowired/*  w w  w. jav a  2s  . c o m*/
public AuthenticationProvider authenticationProvider(
        final AuthenticationUserDetailsService<Authentication> authenticationUserDetailsService) {
    return new AuthenticationProvider() {
        @Override
        public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
            final UserDetails userDetails = authenticationUserDetailsService.loadUserDetails(authentication);
            return new Authentication() {
                @Override
                public Collection<? extends GrantedAuthority> getAuthorities() {
                    return userDetails.getAuthorities();
                }

                @Override
                public Object getCredentials() {
                    return authentication.getCredentials();
                }

                @Override
                public Object getDetails() {
                    return authentication.getDetails();
                }

                public UserDetails getUserDetails() {
                    return userDetails;
                }

                @Override
                public Object getPrincipal() {
                    return userDetails;
                }

                @Override
                public boolean isAuthenticated() {
                    return authentication.isAuthenticated();
                }

                @Override
                public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
                    authentication.setAuthenticated(isAuthenticated);
                }

                @Override
                public String getName() {
                    return authentication.getName();
                }
            };
        }

        @Override
        public boolean supports(Class<?> authentication) {
            return true;
        }
    };
}

From source file:org.akaza.openclinica.control.MainMenuServlet.java

private boolean processForceRenewAuth() throws IOException {
    logger.info("forceRenewAuth is true");
    boolean isRenewAuth = false;
    String renewAuth = (String) request.getParameter("forceRenewAuth");
    if (StringUtils.isNotEmpty(renewAuth)) {
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth != null) {
            auth.setAuthenticated(false);
            SecurityContextHolder.clearContext();
        }/*from  w w  w . j a v a  2s  . c  o m*/
        return true;
    }
    return isRenewAuth;
}

From source file:org.broadleafcommerce.openadmin.server.security.service.AdminSecurityServiceImpl.java

@Override
@Transactional("blTransactionManager")
public AdminUser changePassword(PasswordChange passwordChange) {
    AdminUser user = readAdminUserByUserName(passwordChange.getUsername());
    user.setUnencodedPassword(passwordChange.getNewPassword());
    user = saveAdminUser(user);/*from ww w.  ja  va 2  s .  com*/
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(
            passwordChange.getUsername(), passwordChange.getNewPassword(), auth.getAuthorities());
    SecurityContextHolder.getContext().setAuthentication(authRequest);
    auth.setAuthenticated(false);
    return user;
}

From source file:org.springframework.security.remoting.rmi.ContextPropagatingRemoteInvocation.java

/**
 * Invoked on the server-side.// w  w  w.j  av  a2s  .  c o  m
 * <p>
 * The transmitted principal and credentials will be used to create an unauthenticated
 * {@code Authentication} instance for processing by the {@code AuthenticationManager}.
 *
 * @param targetObject the target object to apply the invocation to
 *
 * @return the invocation result
 *
 * @throws NoSuchMethodException if the method name could not be resolved
 * @throws IllegalAccessException if the method could not be accessed
 * @throws InvocationTargetException if the method invocation resulted in an exception
 */
public Object invoke(Object targetObject)
        throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    if (principal != null) {
        Authentication request = createAuthenticationRequest(principal, credentials);
        request.setAuthenticated(false);
        SecurityContextHolder.getContext().setAuthentication(request);

        if (logger.isDebugEnabled()) {
            logger.debug("Set SecurityContextHolder to contain: " + request);
        }
    }

    try {
        return super.invoke(targetObject);
    } finally {
        SecurityContextHolder.clearContext();

        if (logger.isDebugEnabled()) {
            logger.debug("Cleared SecurityContextHolder.");
        }
    }
}

From source file:pl.bcichecki.rms.customizations.org.springframework.security.web.authentication.www.EventPublisherAwareDigestAuthenticationFilter.java

private Authentication createUnsuccessfulAuthentication(HttpServletRequest request, UserDetails user) {
    Authentication authentication = createSuccessfulAuthentication(request, user);
    authentication.setAuthenticated(false);
    return authentication;
}