Package org.springframework.security.web.authentication.preauth

Examples of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken


            if (tokenValue!=null) {
                AuthorizationToken authToken = oAuth2MgmtService.getTokenFromAccessToken(tokenValue);
                if (authToken!=null&&authToken.getExpirationIn()>0) {
                    final Guest guest = guestService.getGuestById(authToken.guestId);
                    final FlxUserDetails userDetails = new FlxUserDetails(guest);
                    PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(userDetails, authToken,
                            getAuthorities(guest));
                    authentication.setDetails(userDetails);
                    authentication.setAuthenticated(true);
                    SecurityContextHolder.getContext().setAuthentication(authentication);
                } else
                    throw new Exception("No AuthorizationToken found or token expired");

            }
View Full Code Here


        if (viewName.startsWith(REDIRECT_URL_PREFIX)) {
            String location = viewName.substring(REDIRECT_URL_PREFIX.length());
            if (location.startsWith(ADD_CONNECTOR_SUCCESS_CALLBACK_REDIRECT)) {
                final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                if (authentication instanceof PreAuthenticatedAuthenticationToken) {
                    PreAuthenticatedAuthenticationToken authToken = (PreAuthenticatedAuthenticationToken) authentication;
                    final Object credentials = authToken.getCredentials();
                    if (credentials instanceof AuthorizationToken) {
                        AuthorizationToken token = (AuthorizationToken) credentials;
                        final Application applicationForToken = oAuth2MgmtService.getApplicationForToken(token);
                        String addConnectorCallbackURL = applicationForToken.addConnectorCallbackURL;
                        if (addConnectorCallbackURL !=null) {
View Full Code Here

    OAuth2Request storedRequest = new OAuth2Request(parameters, clientId, null, true, scopes, null, null, null, null);
    return storedRequest;
  }

  private Authentication createAuthentication(JsonObject token) {
    return new PreAuthenticatedAuthenticationToken(token.get("sub").getAsString(), token, introspectionAuthorityGranter.getAuthorities(token));
  }
View Full Code Here

     * @param request
     *            用于获取用户IP地址信息,可为Null.
     */
    public static void saveUserDetailsToContext(UserDetails userDetails,
            HttpServletRequest request) {
        PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(
                userDetails, userDetails.getPassword(),
                userDetails.getAuthorities());

        if (request != null) {
            authentication.setDetails(new WebAuthenticationDetails(request));
        }

        SecurityContextHolder.getContext().setAuthentication(authentication);
    }
View Full Code Here

        SecurityContextHolder.getContext().setAuthentication(authentication);
    }

    public static void saveUserDetailsToContext(UserDetails userDetails,
            HttpServletRequest request, SecurityContext securityContext) {
        PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(
                userDetails, userDetails.getPassword(),
                userDetails.getAuthorities());

        if (request != null) {
            authentication.setDetails(new WebAuthenticationDetails(request));
        }

        securityContext.setAuthentication(authentication);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Authentication getAuthentication(org.mule.api.security.Authentication authentication)
    {
        return new PreAuthenticatedAuthenticationToken(authentication.getPrincipal(),
            authentication.getCredentials());
    }
View Full Code Here

  @Override
  public Authentication extract(HttpServletRequest request) {
    String tokenValue = extractToken(request);
    if (tokenValue != null) {
      PreAuthenticatedAuthenticationToken authentication = new PreAuthenticatedAuthenticationToken(tokenValue, "");
      return authentication;
    }
    return null;
  }
View Full Code Here

  }

  @Test
  public void testDetailsAdded() throws Exception {
    Mockito.when(tokenServices.loadAuthentication("FOO")).thenReturn(authentication);
    PreAuthenticatedAuthenticationToken request = new PreAuthenticatedAuthenticationToken("FOO", "");
    request.setDetails("BAR");
    Authentication result = manager.authenticate(request);
    assertEquals(authentication, result);
    assertEquals("BAR", result.getDetails());
  }
View Full Code Here

  @Test
  public void testDetailsEnhanced() throws Exception {
    authentication.setDetails("DETAILS");
    Mockito.when(tokenServices.loadAuthentication("FOO")).thenReturn(authentication);
    PreAuthenticatedAuthenticationToken request = new PreAuthenticatedAuthenticationToken("FOO", "");
    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, "BAR");
    OAuth2AuthenticationDetails details = new OAuth2AuthenticationDetails(servletRequest);
    request.setDetails(details);
    Authentication result = manager.authenticate(request);
    assertEquals(authentication, result);
    assertEquals("BAR", ((OAuth2AuthenticationDetails) result.getDetails()).getTokenValue());
    assertEquals("DETAILS", ((OAuth2AuthenticationDetails) result.getDetails()).getDecodedDetails());
  }
View Full Code Here

    public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
      resources.tokenExtractor(new TokenExtractor() {

        @Override
        public Authentication extract(HttpServletRequest request) {
          return new PreAuthenticatedAuthenticationToken("FOO", "N/A");
        }
      });
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.