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


Java LockedException类代码示例

本文整理汇总了Java中org.springframework.security.authentication.LockedException的典型用法代码示例。如果您正苦于以下问题:Java LockedException类的具体用法?Java LockedException怎么用?Java LockedException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onAuthenticationFailure

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
                                    AuthenticationException exception) throws IOException, ServletException {
	Map<String, Object> result = new HashMap<>();
	result.put("isSuccess", false);
    if (exception instanceof LockedException) {
        // 如果账户被锁定
        logger.info("LoginFailHandler the user is locked!");
        result.put("msg", "该用户被锁定!");
    } else if (exception instanceof UsernameNotFoundException) {
        logger.info("LoginSuccessHandler login fail!");
        result.put("msg", "该帐号不存在!");
    } else {
        logger.info("LoginFailHandler login fail!");
        result.put("msg", "用户名或密码不正确!");
    }
    RequestUtil.responseJson(response, result);
}
 
开发者ID:MinsxCloud,项目名称:minsx-authorization-server,代码行数:19,代码来源:LoginFailHandler.java

示例2: onAuthenticationFailure

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request,
		HttpServletResponse response, AuthenticationException exception)
		throws IOException, ServletException {

	// Is already locked?
	if (exception != null && exception instanceof LockedException) {
		super.onAuthenticationFailure(request, response, exception);
		return;
	}
	
	LoginManager.addFailedLoginAttempt(request.getParameter("j_username"), new Date());
	
	if (ApplicationProperty.PasswordReset.isTrue() && User.findByUserName(request.getParameter("j_username")) != null)
		request.getSession().setAttribute("SUGGEST_PASSWORD_RESET", true);
	
	super.onAuthenticationFailure(request, response, exception);
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:UniTimeAuthenticationFailureHandler.java

示例3: onAuthenticationFailure

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                                    AuthenticationException e) throws IOException, ServletException {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Login failed for user {}.", httpServletRequest.getParameter(SecurityConstants.USERNAME_PARAM));
    }
    final LoginStatus status = new LoginStatus(false, false, null, e.getMessage());
    if (e instanceof LockedException) {
        status.setErrorId("login.locked");
    } else if (e instanceof DisabledException) {
        status.setErrorId("login.disabled");
    } else if (e instanceof UsernameNotFoundException) {
        status.setErrorId("login.error");
    }
    mapper.writeValue(httpServletResponse.getOutputStream(), status);
}
 
开发者ID:kbss-cvut,项目名称:reporting-tool,代码行数:17,代码来源:AuthenticationFailure.java

示例4: authenticate

import org.springframework.security.authentication.LockedException; //导入依赖的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");
	}
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:27,代码来源:AuthenticationEvaluatorImpl.java

示例5: checkCredentials

import org.springframework.security.authentication.LockedException; //导入依赖的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");
	}
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:22,代码来源:AuthenticationEvaluatorImpl.java

示例6: getErrorMessage

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
/**
 * The method is used to extract the error message from the request
 * @param request The request that contains the exception and error message
 * @param key The key is used to find the exception attribute in the request.
 * @return Returns the error message that will be displayed to the user on the login page.
 */
private String getErrorMessage(final HttpServletRequest request, final String key) {

    final Exception exception = (Exception) request.getSession().getAttribute(key);

    String error = "";
    if (exception instanceof BadCredentialsException || exception.getCause() instanceof NullPointerException || exception.getCause() instanceof IllegalArgumentException) {
        LOGGER.debug("Invalid username or password");
        error = messageSource.getMessage("general.login.label.invalidcredentials", null, LocaleContextHolder.getLocale());
    } else if (exception instanceof LockedException) {
        LOGGER.debug("User has been locked");
        error = messageSource.getMessage("general.login.label.userlocked", null ,LocaleContextHolder.getLocale());
    } else if(exception instanceof CredentialsExpiredException){
        LOGGER.debug("User has been inactive");
        error = messageSource.getMessage("general.login.label.userinactive", null ,LocaleContextHolder.getLocale());
    } else {
        LOGGER.error("Unable to login due to unknown reasons");
        LOGGER.error(exception.getMessage(), exception);
        error = messageSource.getMessage("general.login.label.unknownreason", null ,LocaleContextHolder.getLocale());
    }

    return error;
}
 
开发者ID:castlemock,项目名称:castlemock,代码行数:29,代码来源:LoginController.java

示例7: checkAccountStatus

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
/**
 * Tests the status of the LDAP details and throws an appropriate exception.
 * 
 * @param dirContextOperations
 *            The context containing user data.
 * @param username
 *            The username.
 * @throws AuthenticationException
 *             if the status would prevent logging in
 */
private void checkAccountStatus(DirContextOperations dirContextOperations, String username)
        throws AuthenticationException {
    UserDetails ldapDetails = new LdapUserDetailsMapper()
            .mapUserFromContext(dirContextOperations, username,
                    new ArrayList<GrantedAuthority>());
    if (!ldapDetails.isEnabled()) {
        throw new DisabledException("LDAP account is disabled.");
    }
    if (!ldapDetails.isAccountNonLocked()) {
        throw new LockedException("LDAP account is locked.");
    }
    if (!ldapDetails.isCredentialsNonExpired()) {
        throw new CredentialsExpiredException("Credentials for LDAP account are expired.");
    }
    if (!ldapDetails.isAccountNonExpired()) {
        throw new AccountExpiredException("LDAP account is expired.");
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:29,代码来源:LdapAuthenticator.java

示例8: onAuthenticationFailure

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure( HttpServletRequest request, HttpServletResponse response, AuthenticationException exception ) throws IOException, ServletException
{
    final String username = request.getParameter( "j_username" );

    request.getSession().setAttribute( "username", username );

    securityService.registerFailedLogin( username );

    I18n i18n = i18nManager.getI18n();

    if ( ExceptionUtils.indexOfThrowable( exception, LockedException.class )  != -1)
    {
        request.getSession().setAttribute( "LOGIN_FAILED_MESSAGE", i18n.getString( "authentication.message.account.locked" ) );
    }
    else
    {
        request.getSession().setAttribute( "LOGIN_FAILED_MESSAGE", i18n.getString( "authentication.message.account.invalid" ) );
    }


    super.onAuthenticationFailure( request, response, exception );
}
 
开发者ID:dhis2,项目名称:dhis2-core,代码行数:24,代码来源:CustomExceptionMappingAuthenticationFailureHandler.java

示例9: onAuthenticationFailure

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {

    super.onAuthenticationFailure(request, response, exception);

    if (request.getSession(false) == null && !isAllowSessionCreation()) {
        return;
    }

    request.getSession().setAttribute(
            LAST_USERNAME_KEY, request.getParameter(LoginDecisionFilter.USERNAME_PARAMETER)
    );
    request.getSession().setAttribute(
            LAST_PROVIDER_KEY,
            Strings.isNullOrEmpty(request.getParameter("provider"))
                    ? "internal"
                    : request.getParameter("provider")
    );
    request.getSession().setAttribute(IS_LOCKED, false);
    if (exception instanceof LdapAuthenticationProcessException) {
        request.getSession().setAttribute(ERROR_KEY, "login.ldap.internal.user.exists");
    } else if (exception instanceof LockedException) {
        request.getSession().setAttribute(IS_LOCKED, true);
    }
}
 
开发者ID:osiam,项目名称:auth-server,代码行数:27,代码来源:OsiamCachingAuthenticationFailureHandler.java

示例10: getErrorMessage

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
private String getErrorMessage(HttpServletRequest request, String key) {

		Exception exception = (Exception) request.getSession()
				.getAttribute(key);

		String error = "";
		if (exception instanceof BadCredentialsException) {
			error = "Invalid username and password!";
		} else if (exception instanceof LockedException) {
			error = exception.getMessage();
		} else {
			error = "Invalid username and password!";
		}

		return error;
	}
 
开发者ID:gleb619,项目名称:hotel_shop,代码行数:17,代码来源:MainController.java

示例11: retrieveUser

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
/**
 * If user with given username exists and is active then authenticates and returns him. Updates the status of the
 * user when password has been expired.
 *
 * @param username username of user
 * @param authentication data used for authentication
 * @return the user information
 */
@Override
@Transactional
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) {
    MotechUser user = motechUsersDao.findByUserName(username);
    if (user == null) {
        throw new BadCredentialsException(USER_NOT_FOUND);
    } else if (!user.isActive()) {
        throw new LockedException(USER_BLOCKED);
    } else {
        if (settingService.getNumberOfDaysToChangePassword() > 0 &&
                Days.daysBetween(user.getSafeLastPasswordChange(), DateUtil.now()).getDays() >= settingService.getNumberOfDaysToChangePassword()) {
            user.setUserStatus(UserStatus.MUST_CHANGE_PASSWORD);
            motechUsersDao.update(user);
        }
        authentication.setDetails(new MotechUserProfile(user));
        return new User(user.getUserName(), user.getPassword(), user.isActive(), true, !UserStatus.MUST_CHANGE_PASSWORD.equals(user.getUserStatus()),
                !UserStatus.BLOCKED.equals(user.getUserStatus()), authoritiesService.authoritiesFor(user));
    }
}
 
开发者ID:motech,项目名称:motech,代码行数:28,代码来源:MotechAuthenticationProvider.java

示例12: loadUserByUsername

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
@Override
public UserDetails loadUserByUsername(String username)
		throws UsernameNotFoundException {
	Users user=usersRepository.loadUserByUsername(username);
	if (user==null){
		throw new UsernameNotFoundException("Invalid username/password");
	}
	if (user.getFailedLoginAttempts()>=maxFailedAttempts){
		Calendar cal=Calendar.getInstance();
		if (user.getLockoutTime()!=null)
		if (cal.getTimeInMillis()-user.getLockoutTime().getTimeInMillis()>=autoUnlockInterval){
			user.setLockoutTime(null);
			user.setFailedLoginAttemptsToZero();
			return user;
		}
		throw new LockedException("Your account has excceded maximum failed athentication attempts. Please wait 5 minutes to retry.");
	}
	return user;
}
 
开发者ID:tlin-fei,项目名称:ds4p,代码行数:20,代码来源:AccountUserDetailsService.java

示例13: authenticate

import org.springframework.security.authentication.LockedException; //导入依赖的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");
	}
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:27,代码来源:AuthenticationEvaluatorImpl.java

示例14: checkCredentials

import org.springframework.security.authentication.LockedException; //导入依赖的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");
	}
}
 
开发者ID:Evolveum,项目名称:midpoint,代码行数:22,代码来源:AuthenticationEvaluatorImpl.java

示例15: checkIfActive

import org.springframework.security.authentication.LockedException; //导入依赖的package包/类
/**
 * Checks if account is active.
 * @param userAuth user authentication object
 * @param user user object
 * @param throwException throw or not
 * @return the authentication object if {@code user.active == true}
 */
public static UserAuthentication checkIfActive(UserAuthentication userAuth, User user, boolean throwException) {
	if (userAuth == null || user == null || user.getIdentifier() == null) {
		if (throwException) {
			throw new BadCredentialsException("Bad credentials.");
		} else {
			logger.error("Bad credentials.");
			return null;
		}
	} else if (!user.getActive()) {
		if (throwException) {
			throw new LockedException("Account " + user.getId() + " is locked.");
		} else {
			logger.error("Account {} is locked.", user.getId());
			return null;
		}
	}
	return userAuth;
}
 
开发者ID:Erudika,项目名称:para,代码行数:26,代码来源:SecurityUtils.java


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