• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AccountExpiredException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: checkAccountStatus

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的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


示例2: authenticate

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
@Override
public Authentication authenticate(final Authentication authentication) {
    final JwtAuthenticationToken authRequest = (JwtAuthenticationToken) authentication;
    final Jws<Claims> claimsJws = parserAndVerify(authRequest);

    if (claimsJws.getBody().getExpiration() == null) {
        throw new BadCredentialsException("Only temporary JWT supported");
    }

    final String username = claimsJws.getBody().getSubject();
    final UserDetails userDetails;

    try {
        userDetails = userDetailsService.loadUserByUsername(username);
    } catch (final UsernameNotFoundException notFound) {
        throw new BadCredentialsException("Bad credentials");
    }

    if (!userDetails.isAccountNonLocked()) {
        throw new LockedException("User account is locked");
    }

    if (!userDetails.isEnabled()) {
        throw new DisabledException("User is disabled");
    }

    if (!userDetails.isAccountNonExpired()) {
        throw new AccountExpiredException("User account has expired");
    }

    if (!userDetails.isCredentialsNonExpired()) {
        throw new CredentialsExpiredException("User credentials have expired");
    }

    LOG.info("Successful JWT authentication for username={}", userDetails.getUsername());

    return JwtAuthenticationToken.createAuthenticated(userDetails, authRequest.getDetails());
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:39,代码来源:JwtAuthenticationProvider.java


示例3: raiseExceptionForErrorCode

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
private void raiseExceptionForErrorCode(int code, NamingException exception) {
	String hexString = Integer.toHexString(code);
	Throwable cause = new ActiveDirectoryAuthenticationException(hexString,
			exception.getMessage(), exception);
	switch (code) {
	case PASSWORD_EXPIRED:
		throw new CredentialsExpiredException(messages.getMessage(
				"LdapAuthenticationProvider.credentialsExpired",
				"User credentials have expired"), cause);
	case ACCOUNT_DISABLED:
		throw new DisabledException(messages.getMessage(
				"LdapAuthenticationProvider.disabled", "User is disabled"), cause);
	case ACCOUNT_EXPIRED:
		throw new AccountExpiredException(messages.getMessage(
				"LdapAuthenticationProvider.expired", "User account has expired"),
				cause);
	case ACCOUNT_LOCKED:
		throw new LockedException(messages.getMessage(
				"LdapAuthenticationProvider.locked", "User account is locked"), cause);
	default:
		throw badCredentials(cause);
	}
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:24,代码来源:ActiveDirectoryAliasLdapAuthenticationProvider.java


示例4: authenticate

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
@Override
public Authentication authenticate(Authentication auth)
		throws AuthenticationException {
	
	String principal = (String) auth.getPrincipal();
       String password = (String) auth.getCredentials();
       
       //Transformacion de password a MD5
       String passwordMD5 = getPasswordEncoder().encodePassword(password, null);        

	UserDetails details = getUserDetailsService().loadUserByUsername(principal);
       if (principal == null || principal.trim().length() == 0) {
       	throw new BadCredentialsException("Usuario obligatorio", null);
       } else if (password == null || password.trim().length() == 0) {
       	throw new BadCredentialsException("Password obligatoria", null);
       } else if (details == null || !details.getPassword().equals(passwordMD5)) {
		throw new BadCredentialsException("Usuario y/o password no validos", null);
	} else if (!details.isEnabled()) {
		throw new DisabledException("La cuenta ha sido inhabilitada. Contacte con el administrador del sistema.");
	} else if (!details.isAccountNonLocked()) {
		throw new LockedException("La cuenta ha sido bloqueada. Contacte con el administrador del sistema.");
	} else if (!details.isAccountNonExpired()) {
		throw new AccountExpiredException("La cuenta ha caducado. Contacte con el administrador del sistema.");
	} else if (!details.isCredentialsNonExpired()) {
		throw new CredentialsExpiredException("La password ha caducado. Contacte con el administrador del sistema.");
	}
       
       try {
		usersService.updateDateAccess( auth.getPrincipal().toString() );
	} catch (ValidationException | TransactionException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	    return new UsernamePasswordAuthenticationToken(details, passwordMD5, details.getAuthorities());
}
 
开发者ID:ganzux,项目名称:SIRME,代码行数:37,代码来源:BSAuthenticationProvider.java


示例5: handleAuthenticationException

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
/**
 * Evaluates the caught AuthenticationException and updates the user (e.g. disable his account)
 * if necessary and possible. This will only be possible if the authentication's principal has a
 * name (i.e. a.getName() != null).
 *
 * @param e
 *            the exception
 * @param userIdentifier
 *            identifier (email or alias) of the user for whom the authentication was attempted
 * @return the exception that should be rethrown
 * @throws AuthenticationException
 *             the passed exception
 * @throws EmailAlreadyExistsException
 *             when the new email exists
 * @throws AliasAlreadyExistsException
 *             when the new alias exists
 * @throws EmailValidationException
 *             when the email cannot be validated
 * @throws UserActivationValidationException
 *             in case the user cannot be updated
 * @throws InvalidUserStatusTransitionException
 *             when changing the user status is not possible
 * @throws NoClientManagerLeftException
 *             when changing the user status is not possible because the last client manager
 *             would be logged out
 * @throws PermanentIdMissmatchException
 *             when the permanentID changed
 */

private AuthenticationException handleAuthenticationException(AuthenticationException e,
        String userIdentifier) throws AuthenticationException, EmailAlreadyExistsException,
        EmailValidationException, AliasAlreadyExistsException,
        UserActivationValidationException, InvalidUserStatusTransitionException,
        NoClientManagerLeftException, PermanentIdMissmatchException {

    ExternalSystemConfiguration config = getConfiguration();
    // TODO can userId really be null? maybe in case of failed token auth?
    if (config == null || userIdentifier == null) {
        return e;
    }
    ExternalUserVO userVO = new ExternalUserVO();

    userVO.setExternalUserName(userIdentifier);
    userVO.setSystemId(config.getSystemId());
    boolean update = true;
    // handle the different exceptions by setting a new status
    // TODO UsernameNotFoundException should be handled here too, but is dangerous if we have
    // more than one external services and the 1st one does not contain the user
    if (e instanceof AccountExpiredException || e instanceof CredentialsExpiredException
            || e instanceof DisabledException || e instanceof LockedException) {
        userVO.setStatus(UserStatus.TEMPORARILY_DISABLED);
        e = new UserAccountTemporarilyDisabledException(e.getMessage());
        // } else if (e instanceof AuthenticationServiceException) {
        // TODO following correct
        // reactivate account to have normal login as fallback -- no, let communote manager
        // reactivate user account
        // userVO.setStatus(UserStatus.ACTIVE);
    } else if (e instanceof BadCredentialsException) {
        // typically thrown if the password was wrong, the cause might be that the password
        // was changed in the external repository. Theoretically we should call
        // AuthenticationManagement.onInvalidAuthentication if Authentication was a
        // UsernamePasswordAuthentication. But this is the wrong place because several
        // AuthenticationProviders will be called if available. Thus it is possible that some
        // providers fail and the last succeeds but login still fails because of the
        // onInvalidAuthentication logic. Therefore we throw a custom exception which holds the
        // details of the external system.
        e = new BadCredentialsForExternalSystemException(config.getSystemId(), e.getMessage(),
                e.getCause());
        update = false;
    } else {
        // do nothing
        update = false;
    }
    if (update) {
        UserManagement um = getUserManagement();
        um.updateExternalUser(userVO);
    }
    return e;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:80,代码来源:ExternalAuthenticationProvider.java


示例6: authenticate

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
@PerfLogged
@Override
public Authentication authenticate(Authentication authentication)
		throws AuthenticationException {

	if (!(authentication instanceof UsernamePasswordAuthenticationToken))
		throw new IllegalArgumentException(
				"can only authenticate against username+password");
	UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;

	// Determine username
	String username = (auth.getPrincipal() == null) ? "NONE_PROVIDED"
			: auth.getName();

	UserDetails user;

	try {
		user = retrieveUser(username, auth);
		if (user == null)
			throw new IllegalStateException(
					"retrieveUser returned null - a violation of the interface contract");
	} catch (UsernameNotFoundException notFound) {
		if (logger.isDebugEnabled())
			logger.debug("User '" + username + "' not found", notFound);
		throw new BadCredentialsException("Bad credentials");
	}

	// Pre-auth
	if (!user.isAccountNonLocked())
		throw new LockedException("User account is locked");
	if (!user.isEnabled())
		throw new DisabledException("User account is disabled");
	if (!user.isAccountNonExpired())
		throw new AccountExpiredException("User account has expired");
	Object credentials = auth.getCredentials();
	if (credentials == null) {
		logger.debug("Authentication failed: no credentials provided");

		throw new BadCredentialsException("Bad credentials");
	}

	String providedPassword = credentials.toString();
	boolean matched = false;
	synchronized (authCache) {
		AuthCacheEntry pw = authCache.get(username);
		if (pw != null && providedPassword != null) {
			if (pw.valid(providedPassword))
				matched = true;
			else
				authCache.remove(username);
		}
	}
	// Auth
	if (!matched) {
		if (!passwordEncoder.matches(providedPassword, user.getPassword())) {
			logger.debug("Authentication failed: password does not match stored value");

			throw new BadCredentialsException("Bad credentials");
		}
		if (providedPassword != null)
			synchronized (authCache) {
				authCache.put(username, new AuthCacheEntry(providedPassword));
			}
	}

	// Post-auth
	if (!user.isCredentialsNonExpired())
		throw new CredentialsExpiredException(
				"User credentials have expired");

	return createSuccessAuthentication(user, auth, user);
}
 
开发者ID:apache,项目名称:incubator-taverna-server,代码行数:73,代码来源:StrippedDownAuthProvider.java


示例7: authenticate

import org.springframework.security.authentication.AccountExpiredException; //导入依赖的package包/类
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    
	Assert.isInstanceOf(LdapAuthenticationToken.class, authentication,
        messages.getMessage("AbstractUserDetailsAuthenticationProvider.onlySupports",
            "Only UsernamePasswordAuthenticationToken is supported"));

	LdapAuthenticationToken userToken = (LdapAuthenticationToken)authentication;

    String username = userToken.getName();
    
 
    if (!StringUtils.hasLength(username)) {
        throw new BadCredentialsException(messages.getMessage("LdapAuthenticationProvider.emptyUsername",
                "Empty Username"));
    }

    String password = (String) authentication.getCredentials();
    Assert.notNull(password, "Null password was supplied in authentication token");

    if (password.length() == 0) {
        log.debug("Rejecting empty password for user " + username);
        throw new BadCredentialsException(messages.getMessage("LdapAuthenticationProvider.emptyPassword",
                "Empty Password"));
    }

    try {
    	
    	// convert to username/password for bind
    	DirContextOperations userData = getAuthenticator().authenticate(new UsernamePasswordAuthenticationToken(username, password));
        Collection<GrantedAuthority> extraAuthorities = loadUserAuthorities(userData, username, password);
        UserDetails user = userDetailsContextMapper.mapUserFromContext(userData, username, extraAuthorities);

        if( user != null )
        {
            if (!user.isAccountNonLocked()) {
                throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked",
                    "User account is locked"), user);
            }

            if (!user.isEnabled()) {
                throw new DisabledException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled",
                    "User is disabled"), user);
            }

            if (!user.isAccountNonExpired()) {
                throw new AccountExpiredException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.expired",
                    "User account has expired"), user);
            }
        }
        
        log.debug("creating successful authentication");
        return createSuccessfulAuthentication(userToken, user);

    } catch (NamingException ldapAccessFailure) {
        throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure);
    }
    catch(UsernameNotFoundException usernameNotFoundException)
    {
    	throw new BadCredentialsException(usernameNotFoundException.getMessage(), usernameNotFoundException);
    }
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:62,代码来源:UrLdapAuthenticationProvider.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DeprecatedConfigurationProperty类代码示例发布时间:2022-05-22
下一篇:
Java DatabaseSequenceFilter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap