• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AuthenticationException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.security.AuthenticationException的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationException类的具体用法?Java AuthenticationException怎么用?Java AuthenticationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AuthenticationException类属于org.springframework.security包,在下文中一共展示了AuthenticationException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authenticationRequest)
		throws AuthenticationException {
	GrantedAuthority[] authorities = new GrantedAuthorityImpl[authenticationRequest.getAuthorities().length + 1];
	authorities[0] = new GrantedAuthorityImpl(AUTHENTICATED_AUTHORITY_NAME);
	int i = 1;
	for(GrantedAuthority originalAuth : authenticationRequest.getAuthorities()){
		authorities[i] = new GrantedAuthorityImpl(originalAuth.getAuthority());
		i += 1;
	}
	
	UsernamePasswordAuthenticationToken authenticationOutcome = new UsernamePasswordAuthenticationToken(authenticationRequest.getPrincipal(), 
			authenticationRequest.getCredentials(), authorities);
	authenticationOutcome.setDetails(authenticationRequest.getDetails());
	return authenticationOutcome;
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:17,代码来源:ExtensionAuthenticationProvider.java


示例2: shouldConvey_itsBasicProcessingFilter

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Test
public void shouldConvey_itsBasicProcessingFilter() throws IOException, ServletException {
    BasicAuthenticationFilter filter = new BasicAuthenticationFilter(localizer);
    final Boolean[] hadBasicMarkOnInsideAuthenticationManager = new Boolean[]{false};

    filter.setAuthenticationManager(new AuthenticationManager() {
        public Authentication authenticate(Authentication authentication) throws AuthenticationException {
            hadBasicMarkOnInsideAuthenticationManager[0] = BasicAuthenticationFilter.isProcessingBasicAuth();
            return new UsernamePasswordAuthenticationToken("school-principal", "u can be principal if you know this!");
        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));
    MockHttpServletRequest httpRequest = new MockHttpServletRequest();
    httpRequest.addHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("loser:boozer".getBytes()));
    filter.doFilterHttp(httpRequest, new MockHttpServletResponse(), new FilterChain() {
        public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException {

        }
    });
    assertThat(BasicAuthenticationFilter.isProcessingBasicAuth(), is(false));

    assertThat(hadBasicMarkOnInsideAuthenticationManager[0], is(true));
}
 
开发者ID:gocd,项目名称:gocd,代码行数:24,代码来源:BasicAuthenticationFilterTest.java


示例3: setUp

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Before
public void setUp() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = mock(FilterChain.class);
    authenticationException = mock(AuthenticationException.class);
    basicAuth = mock(BasicProcessingFilterEntryPoint.class);
    cruiseLoginFormAuth = mock(AuthenticationEntryPoint.class);
    securityService = mock(SecurityService.class);

    filter = new GoExceptionTranslationFilter();
    filter.setUrlPatternsThatShouldNotBeRedirectedToAfterLogin("(\\.json)|(/images/)");
    filter.setAuthenticationEntryPoint(cruiseLoginFormAuth);
    filter.setBasicAuthenticationEntryPoint(basicAuth);
    filter.setSecurityService(securityService);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:17,代码来源:GoExceptionTranslationFilterTest.java


示例4: commence

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
public void commence(ServletRequest request, ServletResponse response, AuthenticationException authException)
        throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    httpResponse.addHeader("WWW-Authenticate", "Basic realm=\"GoCD\"");
    ArrayList<String> acceptHeader = getAcceptHeader(request);
    String contentType = getMatchingHeader(acceptHeader, "application/vnd\\.go\\.cd\\.v.\\+json");

    if (contentType != null) {
        httpResponse.setContentType(contentType);
        httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        httpResponse.getOutputStream().print("{\n");
        httpResponse.getOutputStream().print("  \"message\": \"You are not authorized to access this resource!\"\n");
        httpResponse.getOutputStream().print("}\n");
        return;
    }
    httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage());
}
 
开发者ID:gocd,项目名称:gocd,代码行数:18,代码来源:BasicProcessingFilterEntryPoint.java


示例5: doFilterHttp

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
protected void doFilterHttp(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    String header = request.getHeader(AUTHORIZATION);//Token token="ACCESS_TOKEN"

    if (header != null) {
        logger.debug("Oauth authorization header: " + header);
        Matcher matcher = OAUTH_TOKEN_PATTERN.matcher(header);
        if (matcher.matches()) {
            String token = matcher.group(1);
            OauthAuthenticationToken authenticationToken = new OauthAuthenticationToken(token);
            try {
                Authentication authResult = authenticationManager.authenticate(authenticationToken);
                SecurityContextHolder.getContext().setAuthentication(authResult);
            } catch (AuthenticationException e) {
                logger.debug("Oauth authentication request for token: " + token, e);
                SecurityContextHolder.getContext().setAuthentication(null);
            }
        }
    }
    chain.doFilter(request, response);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:21,代码来源:OauthAuthenticationFilter.java


示例6: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
/**
 * Authenticate a token
 */
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if( authentication == BAD_CREDENTIALS ) {
        throw new BadCredentialsException( "Bad credentials" );
    } else if( authentication == LOCKED ) {
        throw new LockedException( "Account is locked" );
    }
    return authentication;
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:12,代码来源:TestAuthenticationManager.java


示例7: shouldRaiseAuthenticationExceptionWhenNoMatchForTokenExists

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Test
public void shouldRaiseAuthenticationExceptionWhenNoMatchForTokenExists() {
    when(dataSource.findOauthTokenByAccessToken("token-string")).thenReturn(null);

    try {
        provider.authenticate(new OauthAuthenticationToken("token-string"));
        fail("should have thrown an AuthenticationException");
    } catch (AuthenticationException e) {
        assertThat(e.getMessage(), is("No match for OAuth token: token-string"));
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:12,代码来源:OauthAuthenticationProviderTest.java


示例8: attemptAuthentication

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
public Authentication attemptAuthentication(HttpServletRequest request) throws AuthenticationException {
    PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(null,
            fetchAuthorizationServerAccessToken(request), pluginId(request));

    Authentication authResult = this.getAuthenticationManager().authenticate(authRequest);

    return authResult;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:10,代码来源:PreAuthenticatedRequestsProcessingFilter.java


示例9: sendStartAuthentication

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
protected void sendStartAuthentication(ServletRequest request, ServletResponse response, FilterChain chain,
                                       AuthenticationException reason) throws ServletException, IOException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    //TODO: This is a hack for bug #3175, we should revisit this code in V2.0
    if (isJson(httpRequest) || isJsonFormat(httpRequest)) {
        httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    final Logger logger = LoggerFactory.getLogger(GoExceptionTranslationFilter.class);
    SavedRequest savedRequest = new SavedRequest(httpRequest, getPortResolver());

    logger.debug("Authentication entry point being called; SavedRequest added to Session: {}", savedRequest);

    if (isCreateSessionAllowed() && shouldRedirect(savedRequest.getRequestUrl())) {
        // Store the HTTP request itself. Used by AbstractProcessingFilter
        // for redirection after successful authentication (SEC-29)
        httpRequest.getSession().setAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY,
                savedRequest);
    }

    // SEC-112: Clear the SecurityContextHolder's Authentication, as the
    // existing Authentication is no longer considered valid
    SecurityContextHolder.getContext().setAuthentication(null);

    determineAuthenticationPoint(httpRequest).commence(httpRequest, response, reason);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:30,代码来源:GoExceptionTranslationFilter.java


示例10: onUnsuccessfulAuthentication

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
    super.onUnsuccessfulAuthentication(request, response, failed);
    if (failed.getClass() == AuthenticationServiceException.class) {
        request.getSession().setAttribute(SPRING_SECURITY_LAST_EXCEPTION_KEY, new Exception(localizer.localize("AUTHENTICATION_SERVICE_EXCEPTION")));
        LOGGER.error(failed.getMessage());
        LOGGER.trace(failed.getMessage(), failed);
    }
}
 
开发者ID:gocd,项目名称:gocd,代码行数:10,代码来源:AuthenticationProcessingFilter.java


示例11: getUserDetails

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
public UserDetails getUserDetails(X509Certificate clientCert) throws AuthenticationException {
    X500Principal principal = clientCert.getSubjectX500Principal();
    Matcher cnMatcher = CN_PATTERN.matcher(principal.getName());
    Matcher ouMatcher = OU_PATTERN.matcher(principal.getName());
    if (cnMatcher.find() && ouMatcher.find()) {
        GrantedAuthorityImpl agentAuthority = new GrantedAuthorityImpl(role);
        return new User("_go_agent_" + cnMatcher.group(1), "", true, true, true, true, new GrantedAuthority[]{agentAuthority});
    }
    throw new BadCredentialsException("Couldn't find CN and/or OU for the certificate");
}
 
开发者ID:gocd,项目名称:gocd,代码行数:11,代码来源:X509AuthoritiesPopulator.java


示例12: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    Authentication auth = provider.authenticate(authentication);
    if (auth != null) {
        userService.addUserIfDoesNotExist(UserHelper.getUser(auth));
    }
    return auth;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:8,代码来源:GoAuthenticationProvider.java


示例13: retrieveUser

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    assertPasswordNotBlank(authentication);
    User user = getUserDetailsFromAuthorizationPlugins(username, authentication);

    if (user == null) {
        removeAnyAssociatedPluginRolesFor(username);
        throw new UsernameNotFoundException("Unable to authenticate user: " + username);
    }

    userService.addUserIfDoesNotExist(toDomainUser(user));
    GoUserPrinciple goUserPrinciple = new GoUserPrinciple(user.getUsername(), user.getDisplayName(), "",
            authorityGranter.authorities(user.getUsername()), loginName(username, authentication));
    return goUserPrinciple;
}
 
开发者ID:gocd,项目名称:gocd,代码行数:16,代码来源:PluginAuthenticationProvider.java


示例14: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
public OauthAuthenticationToken authenticate(Authentication authentication) throws AuthenticationException {
    OauthAuthenticationToken authenticationToken = (OauthAuthenticationToken) authentication;
    String token = authenticationToken.getCredentials();
    OauthDataSource.OauthTokenDTO oauthToken = oauthDataSource.findOauthTokenByAccessToken(token);
    if (oauthToken == null) {
        throw new BadCredentialsException("No match for OAuth token: " + token);
    }
    String username = oauthToken.getUserId();
    UserDetails user = new User(username, token, true, true, true, true, oauthAuthority());

    return new OauthAuthenticationToken(user);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:13,代码来源:OauthAuthenticationProvider.java


示例15: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (!supports(authentication.getClass())) {
        return null;
    }

    if (authentication.getCredentials() == null) {
        throw new BadCredentialsException("No pre-authenticated credentials found in request.");
    }

    PreAuthenticatedAuthenticationToken preAuthToken = (PreAuthenticatedAuthenticationToken) authentication;

    return doAuthenticate(preAuthToken);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:15,代码来源:PreAuthenticatedAuthenticationProvider.java


示例16: userAuthenticates

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@When("user <username> authenticates with password <password>")
@Alias("user $username authenticates with password $password")
public void userAuthenticates(@Named(value="username") String username, @Named(value="password") String password) {
  try {
    auth = manager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
    authException = null;
  } catch (AuthenticationException e) {
    auth = null;
    authException = e;
  }
}
 
开发者ID:vactowb,项目名称:jbehave-core,代码行数:12,代码来源:AuthenticationSteps.java


示例17: additionalAuthenticationChecks

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails,
        UsernamePasswordAuthenticationToken token)
        throws AuthenticationException {
    if (!userDetails.getPassword().equals(token.getCredentials().toString())) {
        throw new BadCredentialsException(messages.getMessage(
            "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"),
            userDetails);
    }
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:12,代码来源:RadiusAuthenticationProvider.java


示例18: authenticate

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
	Authentication mockAuth = authentication;
	return mockAuth;
}
 
开发者ID:Rospaccio,项目名称:pentaho-authentication-ext,代码行数:6,代码来源:MockAuthenticationManager.java


示例19: additionalAuthenticationChecks

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
}
 
开发者ID:gocd,项目名称:gocd,代码行数:4,代码来源:PluginAuthenticationProvider.java


示例20: determineUrlToUseForThisRequest

import org.springframework.security.AuthenticationException; //导入依赖的package包/类
@Override protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) {
    Object hasSessionBeenDenied = request.getAttribute(SESSION_DENIED);
    return (hasSessionBeenDenied != null && (Boolean) hasSessionBeenDenied) ? deniedSessionLoginFormUrl : super.determineUrlToUseForThisRequest(request, response, exception);
}
 
开发者ID:gocd,项目名称:gocd,代码行数:5,代码来源:SessionDenialAwareAuthenticationProcessingFilterEntryPoint.java



注:本文中的org.springframework.security.AuthenticationException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FormService类代码示例发布时间:2022-05-23
下一篇:
Java RequestHandler类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap