本文整理匯總了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);
}