当前位置: 首页>>代码示例>>Java>>正文


Java Authentication.setAuthenticated方法代码示例

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


在下文中一共展示了Authentication.setAuthenticated方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticate

import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {

  PersonalCodeAuthentication personalCodeAuthentication = (PersonalCodeAuthentication) authentication.getPrincipal();
  AuthenticatedPerson authenticatedPerson = personalCodeAuthentication.getPrincipal();

  List<? extends GrantedAuthority> updatedAuthorities = grantedAuthorityFactory.from(authenticatedPerson);

  Authentication newUserAuth = new PersonalCodeAuthentication<>(
    authenticatedPerson,
    personalCodeAuthentication.getCredentials(),
    updatedAuthorities);

  newUserAuth.setAuthenticated(true);

  return newUserAuth;
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:18,代码来源:RefreshingAuthenticationManager.java

示例2: doFilterInternal

import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
protected void doFilterInternal(
        HttpServletRequest request,
        HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    final String authHeader = request.getHeader(TOKEN_HEADER);

    if (authHeader != null && authHeader.startsWith(TOKEN_TYPE)) {
        try {
            final String idToken = authHeader.replace(TOKEN_TYPE, "");
            UserPrincipal principal = (UserPrincipal) request
                    .getSession().getAttribute(CURRENT_USER_PRINCIPAL);
            String graphApiToken = (String) request
                    .getSession().getAttribute(CURRENT_USER_PRINCIPAL_GRAPHAPI_TOKEN);
            if (principal == null || graphApiToken == null || graphApiToken.isEmpty()) {
                principal = new UserPrincipal(idToken);
                graphApiToken = acquireTokenForGraphApi(
                        idToken, principal.getClaim().toString()).getAccessToken();
                request.getSession().setAttribute(CURRENT_USER_PRINCIPAL, principal);
                request.getSession().setAttribute(CURRENT_USER_PRINCIPAL_GRAPHAPI_TOKEN, graphApiToken);
            }

            final Authentication authentication = new
                    PreAuthenticatedAuthenticationToken(
                    principal, null,
                    principal.getAuthoritiesByUserGroups(
                            principal.getGroups(graphApiToken),
                            aadAuthFilterProp.getActiveDirectoryGroups()));
            authentication.setAuthenticated(true);
            log.info("Request token verification success. {0}", authentication);
            SecurityContextHolder.getContext().setAuthentication(authentication);
        } catch (Throwable throwable) {
            throw new RuntimeException(throwable);
        }
    }

    filterChain.doFilter(request, response);
}
 
开发者ID:Microsoft,项目名称:azure-spring-boot,代码行数:40,代码来源:AADAuthenticationFilter.java

示例3: validatePasswordFromToken

import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
private Authentication validatePasswordFromToken(final Jws<Claims> tokenData, final Authentication jwtAuth) {
    final String tokenPassword = tokenData.getBody().get("password").toString();
    if(tokenPassword.equals(jwtAuth.getCredentials())) {
        jwtAuth.setAuthenticated(true);
        return jwtAuth;
    }
    return null;
}
 
开发者ID:akraskovski,项目名称:product-management-system,代码行数:9,代码来源:JwtService.java

示例4: getAccessToken

import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest tokenRequest) {
    // grant_type validated in AbstractTokenGranter
    final String clientId = client.getClientId();
    if (clientId == null) {
        log.error("Failed to authenticate client {}", clientId);
        throw new InvalidRequestException("Unknown Client ID.");
    }

    Optional<MobileIDSession> session = genericSessionStore.get(MobileIDSession.class);
    if (!session.isPresent()) {
        return null;
    }
    MobileIDSession mobileIdSession = session.get();

    boolean isComplete = mobileIdAuthService.isLoginComplete(mobileIdSession);
    if (!isComplete) {
        throw new MobileIdAuthNotCompleteException();
    }

    AuthenticatedPerson authenticatedPerson = principalService.getFrom(new Person() {
        @Override
        public String getPersonalCode() {
            return mobileIdSession.personalCode;
        }

        @Override
        public String getFirstName() {
            return mobileIdSession.firstName;
        }

        @Override
        public String getLastName() {
            return mobileIdSession.lastName;
        }
    });

    Authentication userAuthentication =
            new PersonalCodeAuthentication<>(
                    authenticatedPerson,
                    mobileIdSession,
                    grantedAuthorityFactory.from(authenticatedPerson)
            );

    userAuthentication.setAuthenticated(true);

    final OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(client);
    final OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request,
            userAuthentication
    );

    beforeTokenGrantedEventPublisher.publish(oAuth2Authentication);

    return getTokenServices().createAccessToken(oAuth2Authentication);
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:56,代码来源:MobileIdTokenGranter.java

示例5: getAccessToken

import org.springframework.security.core.Authentication; //导入方法依赖的package包/类
@Override
protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest tokenRequest) {
    final String clientId = client.getClientId();
    if (clientId == null) {
        throw new InvalidRequestException("Unknown Client ID.");
    }

    Optional<IdCardSession> session = sessionStore.get(IdCardSession.class);
    if (!session.isPresent()) {
        return null;
    }
    IdCardSession idCardSession = session.get();

    AuthenticatedPerson authenticatedPerson = principalService.getFrom(new Person() {
        @Override
        public String getPersonalCode() {
            return idCardSession.getPersonalCode();
        }

        @Override
        public String getFirstName() {
            return idCardSession.getFirstName();
        }

        @Override
        public String getLastName() {
            return idCardSession.getLastName();
        }
    });

    Authentication userAuthentication = new PersonalCodeAuthentication<>(
            authenticatedPerson,
            idCardSession,
            grantedAuthorityFactory.from(authenticatedPerson));
    userAuthentication.setAuthenticated(true);

    OAuth2Request oAuth2Request = tokenRequest.createOAuth2Request(client);
    OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(oAuth2Request, userAuthentication);

    beforeTokenGrantedEventPublisher.publish(oAuth2Authentication);

    return getTokenServices().createAccessToken(oAuth2Authentication);
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:44,代码来源:IdCardTokenGranter.java


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