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


Java AccountException类代码示例

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


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

示例1: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * 认证回调函数,登录时调用.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authcToken) throws AuthenticationException {
	UsernamePassword2Token token = (UsernamePassword2Token) authcToken;
	String username = token.getUsername();
	if (username == null || null == username) {
		throw new AccountException(
				"Null usernames are not allowed by this realm.");
	}
	User entity = new User();
	entity.setEmail(username);
	entity.setStatus(Constant.STATUS_ENABLED);
	entity = (User) service.iUserService.select(entity);
	if (null == entity) {
		throw new UnknownAccountException("No account found for user ["
				+ username + "]");
	}
	byte[] key = Encode.decodeHex(entity.getRandom());
	return new SimpleAuthenticationInfo(new Shiro(entity.getId(),
			entity.getEmail(), entity.getName()), entity.getPassword(),
			ByteSource.Util.bytes(key), getName());
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:26,代码来源:Authorizing2Realm.java

示例2: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if(!(token instanceof UsernamePasswordToken)) {
        throw new IllegalStateException("Token has to be instance of UsernamePasswordToken class");
    }
    
    UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken)token;
    if (usernamePasswordToken.getUsername() == null) {
        throw new AccountException("Null usernames are not allowed by this realm.");
    }
    
    AppUser user = service.getAppUser(usernamePasswordToken.getUsername());
    if(user == null) {
        throw new AuthenticationException("Could not find user");
    }
    
    if(getCredentialsMatcher().doCredentialsMatch(usernamePasswordToken, user.getAsAuthenticationInfo())) {
        return user.getAsAuthenticationInfo();
    }

    throw new AuthenticationException("Failed to authenticate!");
}
 
开发者ID:felixhusse,项目名称:bookery,代码行数:23,代码来源:JPARealm.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  UsernamePasswordToken upToken = (UsernamePasswordToken) token;
  String username = upToken.getUsername();

  // Null username is invalid
  if(username == null) {
    throw new AccountException("Null usernames are not allowed by this realm.");
  }

  User user = userService.findActiveUser(username);
  if(user == null) user = userService.findActiveUserByEmail(username);
  if(user == null || !user.isEnabled() || !user.getRealm().equals(AGATE_REALM))
    throw new UnknownAccountException("No account found for user [" + username + "]");

  username = user.getName();
  UserCredentials userCredentials = userService.findUserCredentials(username);
  if(userCredentials == null) throw new UnknownAccountException("No account found for user [" + username + "]");

  SimpleAuthenticationInfo authInfo = new SimpleAuthenticationInfo(username, userCredentials.getPassword(), getName());
  authInfo.setCredentialsSalt(new SimpleByteSource(salt));
  return authInfo;
}
 
开发者ID:obiba,项目名称:agate,代码行数:24,代码来源:AgateUserRealm.java

示例4: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * 用户登录的身份验证方法
 * 
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;

       String username = usernamePasswordToken.getUsername();
       
       if (username == null) {
           throw new AccountException("用户名不能为空");
       }
       
       User user = accountManager.getUserByUsername(username);
       
       if (user == null) {
           throw new UnknownAccountException("用户不存在");
       }
       
       if (user.getState().equals(State.Disable.getValue())) {
       	 throw new DisabledAccountException("你的账户已被禁用,请联系管理员开通.");
       }
       
       SessionVariable model = new SessionVariable(user);
       
       return new SimpleAuthenticationInfo(model,user.getPassword(),getName());
}
 
开发者ID:extion,项目名称:base-framework,代码行数:28,代码来源:JdbcAuthenticationRealm.java

示例5: toResponse

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
public Response toResponse(ShiroException exception) {

    Status status = Status.FORBIDDEN; // Invalid api key
    if (exception instanceof AccountException) {
        // API key missing
        status = Status.BAD_REQUEST;
        logger.warn(exception.getMessage());
    } else if (exception instanceof AuthorizationException) {
        // Not enough permissions
        status = Status.UNAUTHORIZED;
        logger.warn(exception.getMessage());
    } else {
        logger.error(exception.getMessage(), exception);
    }
    return Response.status(status).type(MediaType.APPLICATION_JSON)
            .entity(ErrorEntity.with().message(exception.getMessage()).build()).build();
}
 
开发者ID:antoniomaria,项目名称:gazpachoquest,代码行数:19,代码来源:ShiroExceptionHandler.java

示例6: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * 认证回调函数, 登录时调用
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken token) throws AuthenticationException {
	
	System.out.println("------!");
	
	UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
	String username = usernamePasswordToken.getUsername();
       
	if (username == null) {
           throw new AccountException("用户名不能为空");
       }
       User user = null;//userService.getByUserName(username);
       if (user == null) {
           throw new UnknownAccountException("用户不存在");
       }

       return new SimpleAuthenticationInfo(user,user.getPassword(),getName());
}
 
开发者ID:cncduLee,项目名称:bbks,代码行数:23,代码来源:SystemRealm.java

示例7: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 *  认证信息,主要针对用户登录, 
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authcToken) throws AuthenticationException {
	
	ShiroToken token = (ShiroToken) authcToken;
	User user = null;
	try {
		user = userService.login(token.getUsername(), token.getPswd());
	} catch (Exception e) {
		throw new AccountException(e);
	}

	return new SimpleAuthenticationInfo(user, token.getPswd(), getName());
   }
 
开发者ID:miracle857,项目名称:weibo,代码行数:18,代码来源:SampleRealm.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@SuppressWarnings("unused")
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken arg0)
    throws AuthenticationException
{
    ShiroToken token = (ShiroToken) arg0;
    String username = token.getUsername();

    // 根据username从数据库查找用户,得到密码
    // 假设找到的用户如下
    // User user = userService.findByUsername(username)
    User user = new User();
    user.setName(username);
    user.setPassword("21232f297a57a5a743894a0e4a801fc3"); // 数据库中的密码md5加密的

    if (null == user)
    {
        throw new AccountException("username is not exist");
    }
    else if (!user.getPassword().equals(token.getPswd()))
    {
        throw new AccountException("password is not right");
    }
    else
    {
        // 登陆成功
        logger.info("{} login success.", username);
    }
    return new SimpleAuthenticationInfo(arg0, user.getPassword(), username);
}
 
开发者ID:peterchenhdu,项目名称:spring-shiro-demo,代码行数:31,代码来源:UserRealm.java

示例9: onLoginFailure

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@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);
}
 
开发者ID:xiangxik,项目名称:java-platform,代码行数:29,代码来源:AjaxAuthenticationFilter.java

示例10: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) {
  UsernamePasswordToken upToken = (UsernamePasswordToken) token;

  CUser user;
  try {
    user = configuration.readUser(upToken.getUsername());
  }
  catch (UserNotFoundException e) {
    throw new AccountException("User '" + upToken.getUsername() + "' cannot be retrieved.", e);
  }

  if (user.getPassword() == null) {
    throw new AccountException("User '" + upToken.getUsername() + "' has no password, cannot authenticate.");
  }

  if (CUser.STATUS_ACTIVE.equals(user.getStatus())) {
    // 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() + "'.");
  }
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:34,代码来源:AuthenticatingRealmImpl.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authToken)
    throws AuthenticationException {
  UsernamePasswordToken token = (UsernamePasswordToken) authToken;
  if (StringUtils.isBlank(token.getUsername())) {
    throw new AccountException("Empty usernames are not allowed by this realm.");
  }
  String loginPayload = createLoginPayload(token.getUsername(), token.getPassword());
  User user = authenticateUser(loginPayload);
  LOG.debug("{} successfully login via ZeppelinHub", user.login);
  return new SimpleAuthenticationInfo(user.login, token.getPassword(), name);
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:13,代码来源:ZeppelinHubRealm.java

示例12: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken at) throws AuthenticationException {
    log.debug("getting authc info for {}", at);
    
    ClothoAccount account = store.getAccount(((UsernamePasswordToken) at).getUsername());
    if (!account.isAuthenticatable()) throw new AccountException("Cannot authenticate as " + at.getPrincipal().toString());
    return account;
}
 
开发者ID:CIDARLAB,项目名称:clotho3crud,代码行数:9,代码来源:ClothoRealm.java

示例13: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * Method description
 * 
 * 
 * @param token
 * 
 * @param authToken
 * 
 * @return
 * 
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authToken) throws AuthenticationException {
	if (!(authToken instanceof PublicKeyToken)) {
		throw new UnsupportedTokenException("PublicKeyToken is required");
	}

	PublicKeyToken token = (PublicKeyToken) authToken;

	AuthenticationInfo info = null;
	AuthenticationResult result = authenticator.authenticate(
			token.getUsername(), token.getPublicKey());

	if ((result != null)
			&& (AuthenticationState.SUCCESS == result.getState())) {
		info = createAuthenticationInfo(token, result);
	} else if ((result != null)
			&& (AuthenticationState.NOT_FOUND == result.getState())) {
		throw new UnknownAccountException("unknown account ".concat(token
				.getUsername()));
	} else {
		throw new AccountException("authentication failed");
	}

	return info;
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:39,代码来源:ScmPublicKeyRealm.java

示例14: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * Method description
 * 
 * 
 * @param token
 * 
 * @param authToken
 * 
 * @return
 * 
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authToken) throws AuthenticationException {
	if (!(authToken instanceof UsernamePasswordToken)) {
		throw new UnsupportedTokenException(
				"ScmAuthenticationToken is required");
	}

	UsernamePasswordToken token = (UsernamePasswordToken) authToken;

	AuthenticationInfo info = null;
	AuthenticationResult result = authenticator.authenticate(null, null,
			token.getUsername(), new String(token.getPassword()));

	if ((result != null)
			&& (AuthenticationState.SUCCESS == result.getState())) {
		info = createAuthenticationInfo(token, result);
	} else if ((result != null)
			&& (AuthenticationState.NOT_FOUND == result.getState())) {
		throw new UnknownAccountException("unknown account ".concat(token
				.getUsername()));
	} else {
		throw new AccountException("authentication failed");
	}

	return info;
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:40,代码来源:ScmPasswordRealm.java

示例15: doGetAuthenticationInfo

import org.apache.shiro.authc.AccountException; //导入依赖的package包/类
/**
 * 根据认证方式(如表单)获取用户名称、密码
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	UsernamePasswordToken upToken = (UsernamePasswordToken) token;
	String username = upToken.getUsername();
	if (username == null) {
		log.warn("用户名不能为空");
		throw new AccountException("用户名不能为空");
	}

	User user = null;
	try {
		user = userManager.findUserByName(username);
	} catch(Exception ex) {
		log.warn("获取用户失败\n" + ex.getMessage());
	}
	if (user == null) {
	    log.warn("用户不存在");
	    throw new UnknownAccountException("用户不存在");
	}
	if(user.getEnabled() == null || "2".equals(user.getEnabled())) {
	    log.warn("用户被禁止使用");
	    throw new UnknownAccountException("用户被禁止使用");
	}
	log.info("用户【" + username + "】登录成功");
	byte[] salt = EncodeUtils.hexDecode(user.getSalt());
	ShiroPrincipal subject = new ShiroPrincipal(user);
	return new SimpleAuthenticationInfo(subject, user.getPassword(), ByteSource.Util.bytes(salt), getName());
}
 
开发者ID:shaisxx,项目名称:snaker-demo,代码行数:32,代码来源:ShiroAuthorizingRealm.java


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