本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}