本文整理匯總了Java中org.springframework.security.authentication.AuthenticationServiceException類的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationServiceException類的具體用法?Java AuthenticationServiceException怎麽用?Java AuthenticationServiceException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AuthenticationServiceException類屬於org.springframework.security.authentication包,在下文中一共展示了AuthenticationServiceException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: extractUserData
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void extractUserData(ObjectNode jsonUser, ExternalUserVO userVO)
throws AuthenticationServiceException {
assertFieldsExist(jsonUser, JSON_PARAM_LOGIN, JSON_PARAM_EMAIL, JSON_PARAM_LAST_NAME,
JSON_PARAM_FIRST_NAME);
userVO.setExternalUserName(jsonUser.get(JSON_PARAM_LOGIN).asText());
userVO.setEmail(jsonUser.get(JSON_PARAM_EMAIL).asText());
userVO.setLastName(jsonUser.get(JSON_PARAM_LAST_NAME).asText());
userVO.setFirstName(jsonUser.get(JSON_PARAM_FIRST_NAME).asText());
if (jsonUser.has(JSON_PARAM_LANG)) {
String lang = jsonUser.get(JSON_PARAM_LANG).asText();
Locale locale = new Locale(lang);
userVO.setDefaultLanguage(locale);
}
}
示例2: extract
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public String extract(String header) {
if (header == null || "".equals(header)) {
throw new AuthenticationServiceException(
"Authorization header cannot be blank!"
);
}
if (header.length() < HEADER_PREFIX.length()) {
throw new AuthenticationServiceException(
"Invalid authorization header size."
);
}
return header.substring(HEADER_PREFIX.length(), header.length());
}
示例3: getJwtClaims
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
private JwtClaims getJwtClaims(String token) {
HttpsJwks httpsJkws = new HttpsJwks(jwksBaseURL);
HttpsJwksVerificationKeyResolver httpsJwksKeyResolver = new HttpsJwksVerificationKeyResolver(httpsJkws);
JwtConsumer jwtConsumer = new JwtConsumerBuilder().setRequireExpirationTime().setAllowedClockSkewInSeconds(3600)
.setExpectedIssuer(jwksIssuer)
// whom the JWT needs to have been issued by
.setExpectedAudience(jwksAudience).setVerificationKeyResolver(httpsJwksKeyResolver).build();
try {
// Validate the JWT and process it to the Claims
JwtClaims jwtClaims = jwtConsumer.processToClaims(token);
return jwtClaims;
} catch (InvalidJwtException e) {
// Anyway here throws the exception , so no need to log the error.
// log the error if required from where this function invokes
// logger.error("Invalid JWT! " + e);
throw new AuthenticationServiceException("Invalid Token");
}
}
示例4: retrieveUser
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
/**
* Implementation of an abstract method defined in the base class. The
* retrieveUser() method is called by authenticate() method of the base
* class. The latter is called by the AuthenticationManager.
*/
@Override
protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException {
UserDetails details;
try {
details = this.getUserDetailsService().loadUserByUsername(username);
authentication.setDetails(details);
}
catch (DataAccessException repositoryProblem) {
throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem);
}
if (details == null) {
throw new AuthenticationServiceException(
"UserDetailsService returned null, which is an interface contract violation");
}
return details;
}
開發者ID:melthaw,項目名稱:spring-backend-boilerplate,代碼行數:24,代碼來源:UserDetailsAuthenticationProviderImpl.java
示例5: verifiedToken
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@NotNull
public static Map<String, Object> verifiedToken(String token, String publicKey) {
Jwt jwt = JwtHelper.decode(token);
// Currently not sure how we should handle this because we have multiple
// CF instances. We would need to have a central file for all UAA
// instances
// verifySignature(jwt, publicKey);
Map<String, Object> tokenObj = tryExtractToken(jwt);
if (tokenObj == null) {
throw new AuthenticationServiceException("Error parsing JWT token/extracting claims");
}
verifyExpiration(tokenObj);
return tokenObj;
}
示例6: authenticate
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
if (!supports(authentication.getClass())) {
return null;
}
UaaRelyingPartyToken auth = (UaaRelyingPartyToken) authentication;
Map<String, Object> tokenObj = UaaFilterUtils.verifiedToken(auth.getToken(), publicKey);
UaaUserDetails userDetails = new UaaUserDetails();
userDetails.setUsername(tokenObj.get(Properties.USER_NAME).toString());
userDetails.setGrantedAuthorities(scopeToGrantedAuthority((List<String>) tokenObj.get(Properties.SCOPE)));
if (!userDetails.isEnabled()) {
throw new AuthenticationServiceException("User is disabled");
}
return createSuccessfulAuthentication(userDetails);
}
示例7: attemptAuthentication
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
if (!HttpMethod.POST.name().equals(request.getMethod()) || !WebUtil.isAjax(request)) {
if(logger.isDebugEnabled()) {
logger.debug("Authentication method not supported. Request method: " + request.getMethod());
}
throw new AuthMethodNotSupportedException("Authentication method not supported");
}
LoginRequest loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class);
if (StringUtils.isBlank(loginRequest.getUsername()) || StringUtils.isBlank(loginRequest.getPassword())) {
throw new AuthenticationServiceException("Username or Password not provided");
}
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());
return this.getAuthenticationManager().authenticate(token);
}
示例8: attemptAuthentication
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException,
ServletException {
if (!HttpMethod.POST.name().equals(request.getMethod()) || !WebUtil.isAjax(request)) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication method not supported. Request method: " + request.getMethod());
}
throw new AuthMethodNotSupportedException("Authentication method not supported");
}
LoginRequest loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class);
if (StringUtils.isBlank(loginRequest.getUsername()) || StringUtils.isBlank(loginRequest.getPassword())) {
throw new AuthenticationServiceException("Username or Password not provided");
}
AdminUserAuthenticationToken token = new AdminUserAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());
return this.getAuthenticationManager().authenticate(token);
}
示例9: attemptAuthentication
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
if (!HttpMethod.POST.name().equals(request.getMethod()) || !WebUtil.isAjax(request)) {
if(logger.isDebugEnabled()) {
logger.debug("Authentication method not supported. Request method: " + request.getMethod());
}
throw new AuthMethodNotSupportedException("Authentication method not supported");
}
LoginRequest loginRequest = objectMapper.readValue(request.getReader(), LoginRequest.class);
if (StringUtils.isBlank(loginRequest.getUsername()) || StringUtils.isBlank(loginRequest.getPassword())) {
throw new AuthenticationServiceException("Username or Password not provided");
}
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(loginRequest.getUsername(), loginRequest.getPassword());
return this.getAuthenticationManager().authenticate(token);
}
示例10: attemptAuthentication
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
if (!HttpMethod.POST.name().equals(request.getMethod())) {
if (logger.isDebugEnabled()) {
logger.debug("Authentication method not supported. Request method: " + request.getMethod());
}
throw new AuthMethodNotSupportedException("Authentication method not supported");
}
RefreshTokenRequest refreshTokenRequest;
try {
refreshTokenRequest = objectMapper.readValue(request.getReader(), RefreshTokenRequest.class);
} catch (Exception e) {
throw new AuthenticationServiceException("Invalid refresh token request payload");
}
if (StringUtils.isBlank(refreshTokenRequest.getRefreshToken())) {
throw new AuthenticationServiceException("Refresh token is not provided");
}
RawAccessJwtToken token = new RawAccessJwtToken(refreshTokenRequest.getRefreshToken());
return this.getAuthenticationManager().authenticate(new RefreshAuthenticationToken(token));
}
示例11: attemptAuthentication
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) {
if (!request.getMethod().equals("POST")) {
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
}
final String username = obtainUsername(request);
final String password = obtainPassword(request);
final String receivedOtp = obtainOneTimeToken(request);
final OneTimePasswordAuthenticationToken authRequest =
new OneTimePasswordAuthenticationToken(username, password, receivedOtp);
authRequest.setDetails(authenticationDetailsSource.buildDetails(request));
return this.getAuthenticationManager().authenticate(authRequest);
}
示例12: retrieveUser
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
/**
* Retrieve user.
*
* @param username
* the username
* @param authentication
* the authentication
* @return the user details
* @throws AuthenticationException
* the authentication exception
*/
@Override
protected UserDetails retrieveUser(final String username, final UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
UserDetails loadedUser;
if (username == null || username.trim().length() < 1) {
throw new AuthenticationServiceException(authenticationServiceExcep);
}
try {
System.out.println(authenticationService);
loadedUser = authenticationService.loadUserByUsername(username);
} catch (final DataAccessException repositoryProblem) {
throw new AuthenticationServiceException(authenticationServiceExcep);
}
if (loadedUser == null) {
throw new AuthenticationServiceException(badCredentialExcep);
}
return loadedUser;
}
示例13: retrieveUser
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
String password = authentication.getCredentials().toString();
UserDetails existingUser;
try {
ResponseEntity<Collection<? extends GrantedAuthority>> authenticationResponse = authenticationDelegate.authenticate(username, password.toCharArray());
if (authenticationResponse.getStatusCode().value() == 401) {
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
existingUser = new User(username, password, authenticationResponse.getBody());
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
throw new AuthenticationServiceException(ex.getMessage(), ex);
}
return existingUser;
}
示例14: authenticate
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public UsernamePasswordAuthenticationToken authenticate(ConnectionEnvironment connEnv, T authnCtx)
throws BadCredentialsException, AuthenticationCredentialsNotFoundException, DisabledException, LockedException,
CredentialsExpiredException, AuthenticationServiceException, AccessDeniedException, UsernameNotFoundException {
checkEnteredCredentials(connEnv, authnCtx);
MidPointPrincipal principal = getAndCheckPrincipal(connEnv, authnCtx.getUsername(), true);
UserType userType = principal.getUser();
CredentialsType credentials = userType.getCredentials();
CredentialPolicyType credentialsPolicy = getCredentialsPolicy(principal, authnCtx);
if (checkCredentials(principal, authnCtx, connEnv)) {
recordPasswordAuthenticationSuccess(principal, connEnv, getCredential(credentials), credentialsPolicy);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(principal,
authnCtx.getEnteredCredential(), principal.getAuthorities());
return token;
} else {
recordPasswordAuthenticationFailure(principal, connEnv, getCredential(credentials), credentialsPolicy, "password mismatch");
throw new BadCredentialsException("web.security.provider.invalid");
}
}
示例15: checkCredentials
import org.springframework.security.authentication.AuthenticationServiceException; //導入依賴的package包/類
@Override
public UserType checkCredentials(ConnectionEnvironment connEnv, T authnCtx)
throws BadCredentialsException, AuthenticationCredentialsNotFoundException, DisabledException, LockedException,
CredentialsExpiredException, AuthenticationServiceException, AccessDeniedException, UsernameNotFoundException {
checkEnteredCredentials(connEnv, authnCtx);
MidPointPrincipal principal = getAndCheckPrincipal(connEnv, authnCtx.getUsername(), false);
UserType userType = principal.getUser();
CredentialsType credentials = userType.getCredentials();
CredentialPolicyType credentialsPolicy = getCredentialsPolicy(principal, authnCtx);
if (checkCredentials(principal, authnCtx, connEnv)) {
return userType;
} else {
recordPasswordAuthenticationFailure(principal, connEnv, getCredential(credentials), credentialsPolicy, "password mismatch");
throw new BadCredentialsException("web.security.provider.invalid");
}
}