org.apache.shiro.authc.CredentialsException Java Examples
The following examples show how to use
org.apache.shiro.authc.CredentialsException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCredentialsSecurerSupport.java From super-cloudops with Apache License 2.0 | 6 votes |
@Override public boolean validate(@NotNull CredentialsToken token, @NotNull AuthenticationInfo info) throws CredentialsException, RuntimeException { /* * Password is a string that may be set to empty. * See:xx.realm.GeneralAuthorizingRealm#doAuthenticationInfo */ notNullOf(info, "storedCredentials"); notNullOf(info.getCredentials(), "storedCredentials"); // Delegate validate. if (!isNull(delegate) && !token.isSolved()) { return delegate.validate(resolves(token), info); } // # Assertion compare request credentials & storage credentials. return isEqual(toBytes(signature(token)), toBytes(info.getCredentials())); }
Example #2
Source File: GlobalExceptionHandler.java From MeetingFilm with Apache License 2.0 | 5 votes |
/** * 账号密码错误异常 */ @ExceptionHandler(CredentialsException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) public String credentials(CredentialsException e, Model model) { String username = getRequest().getParameter("username"); LogManager.me().executeLog(LogTaskFactory.loginLog(username, "账号密码错误", getIp())); model.addAttribute("tips", "账号密码错误"); return "/login.html"; }
Example #3
Source File: GlobalExceptionHandler.java From WebStack-Guns with MIT License | 5 votes |
/** * 账号密码错误异常 */ @ExceptionHandler(CredentialsException.class) @ResponseStatus(HttpStatus.UNAUTHORIZED) public String credentials(CredentialsException e, Model model) { String username = getRequest().getParameter("username"); LogManager.me().executeLog(LogTaskFactory.loginLog(username, "账号密码错误", getIp())); model.addAttribute("tips", "账号密码错误"); return "/login.html"; }
Example #4
Source File: AjaxAuthenticationFilter.java From java-platform with Apache License 2.0 | 5 votes |
@Override protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, ServletResponse response) { if (WebHelper.isAjax((HttpServletRequest) request)) { Result result = Result.failure(); if (e instanceof IncorrectCredentialsException) { result.message("密码错误"); } else if (e instanceof ExpiredCredentialsException) { result.message("密码已过期"); } else if (e instanceof UnknownAccountException) { result.message("该账号不存在"); } else if (e instanceof DisabledAccountException) { result.message("该账号已禁用"); } else if (e instanceof LockedAccountException) { result.message("该账号已锁定"); } else if (e instanceof AccountException) { result.message("账号错误"); } else if (e instanceof CredentialsException) { result.message("密码错误"); } try { writeObject(request, response, result); } catch (IOException ex) { throw new RuntimeException(ex); } return false; } return super.onLoginFailure(token, e, request, response); }
Example #5
Source File: AuthenticatingRealmImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) { UsernamePasswordToken upToken = (UsernamePasswordToken) token; CUser user; try { user = configuration.readUser(upToken.getUsername()); } catch (UserNotFoundException e) { throw new UnknownAccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e); } if (user.getPassword() == null) { throw new CredentialsException("User '" + upToken.getUsername() + "' has no password, cannot authenticate."); } if (user.isActive()) { // Check for legacy user that has unsalted password hash // Update if unsalted password hash and valid credentials were specified if (hasLegacyPassword(user) && isValidCredentials(upToken, user)) { reHashPassword(user, new String(upToken.getPassword())); } return createAuthenticationInfo(user); } else if (CUser.STATUS_DISABLED.equals(user.getStatus())) { throw new DisabledAccountException("User '" + upToken.getUsername() + "' is disabled."); } else { throw new AccountException( "User '" + upToken.getUsername() + "' is in illegal status '" + user.getStatus() + "'."); } }
Example #6
Source File: AuthenticatingRealmImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test public void testEmptyPassword() throws Exception { buildTestAuthenticationConfig(CUser.STATUS_ACTIVE); UsernamePasswordToken upToken = new UsernamePasswordToken("username", (String) null); thrown.expect(CredentialsException.class); realm.getAuthenticationInfo(upToken); }
Example #7
Source File: CredentialsSecurerAdapter.java From super-cloudops with Apache License 2.0 | 4 votes |
@Override public boolean validate(@NotNull CredentialsToken token, @NotNull AuthenticationInfo info) throws CredentialsException, RuntimeException { return securer.validate(token, info); }
Example #8
Source File: FastCasAuthorizingRealm.java From super-cloudops with Apache License 2.0 | 4 votes |
/** * Authenticates a user and retrieves its information. * * @param token * the authentication token * @throws AuthenticationException * if there is an error during authentication. */ @Override protected IamAuthenticationInfo doAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String granticket = EMPTY; try { notNullOf(token, "authenticationToken"); FastCasAuthenticationToken ftk = (FastCasAuthenticationToken) token; // Get request flash grant ticket(May be empty) granticket = (String) ftk.getCredentials(); // Contact CAS remote server to validate ticket TicketValidatedAssertModel<IamPrincipalInfo> validated = doRequestRemoteTicketValidation(granticket); // Grant ticket assertion . assertTicketValidation(validated); /** * {@link JedisIamSessionDAO#update()} </br> * Update session expire date time. */ Date validUntilDate = validated.getValidUntilDate(); long maxIdleTimeMs = validUntilDate.getTime() - currentTimeMillis(); state(maxIdleTimeMs > 0, format("Remote authenticated response session expired time: %s invalid, maxIdleTimeMs: %s", validUntilDate, maxIdleTimeMs)); getSession().setTimeout(maxIdleTimeMs); IamPrincipalInfo info = validated.getPrincipalInfo(); // Storage authenticated attributes. bind(KEY_LANG_NAME, info.getAttributes().get(KEY_LANG_NAME)); bind(KEY_PARENT_SESSIONID_NAME, info.getAttributes().get(KEY_PARENT_SESSIONID_NAME)); bind(KEY_DATA_CIPHER_NAME, info.getAttributes().get(KEY_DATA_CIPHER_NAME)); bind(KEY_ACCESSTOKEN_SIGN_NAME, info.getAttributes().get(KEY_ACCESSTOKEN_SIGN_NAME)); // Update settings grant ticket String newGrantTicket = valueOf(info.getStoredCredentials()); ftk.setCredentials(newGrantTicket); // Attribute of remember String principal = validated.getPrincipalInfo().getPrincipal(); ftk.setPrincipal(principal); // MARK1 ftk.setRememberMe(parseBoolean(info.getAttributes().get(KEY_REMEMBERME_NAME))); log.info("Validated grantTicket: {}, principal: {}", granticket, principal); // Authenticate attributes.(roles/permissions/rememberMe) PrincipalCollection principals = createPermitPrincipalCollection(info); // You should always use token credentials because the default // SimpleCredentialsMatcher checks. return new FastAuthenticationInfo(info, principals, getName()); } catch (Exception e) { throw new CredentialsException(format("Unable to validate ticket [%s]", granticket), e); } }
Example #9
Source File: CredentialsSecurer.java From super-cloudops with Apache License 2.0 | 2 votes |
/** * Validation credentials * * @param token * External input principal and credentials * @param info * Database storage credentials information. * @return */ default boolean validate(@NotNull CredentialsToken token, @NotNull AuthenticationInfo info) throws CredentialsException, RuntimeException { throw new UnsupportedOperationException(); }