當前位置: 首頁>>代碼示例>>Java>>正文


Java UsernamePasswordToken.getPassword方法代碼示例

本文整理匯總了Java中org.apache.shiro.authc.UsernamePasswordToken.getPassword方法的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordToken.getPassword方法的具體用法?Java UsernamePasswordToken.getPassword怎麽用?Java UsernamePasswordToken.getPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authc.UsernamePasswordToken的用法示例。


在下文中一共展示了UsernamePasswordToken.getPassword方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
		throws AuthenticationException {
	UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("enable", 1);
	params.put("account", token.getUsername());
	Parameter parameter = new Parameter("sysUserService", "queryList").setMap(params);
	logger.info("{} execute sysUserService.queryList start...", parameter.getNo());
	List<?> list = provider.execute(parameter).getList();
	logger.info("{} execute sysUserService.queryList end.", parameter.getNo());
	if (list.size() == 1) {
		SysUser user = (SysUser) list.get(0);
		StringBuilder sb = new StringBuilder(100);
		for (int i = 0; i < token.getPassword().length; i++) {
			sb.append(token.getPassword()[i]);
		}
		if (user.getPassword().equals(sb.toString())) {
			WebUtil.saveCurrentUser(user.getId());
			saveSession(user.getAccount(), token.getHost());
			AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(),
					user.getUserName());
			return authcInfo;
		}
		logger.warn("USER [{}] PASSWORD IS WRONG: {}", token.getUsername(), sb.toString());
		return null;
	} else {
		logger.warn("No user: {}", token.getUsername());
		return null;
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:31,代碼來源:Realm.java

示例2: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
	 * 認證回調函數,登錄時調用.
	 */
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
//		User user = accountManager.findUserByLoginName(token.getUsername());
		
		//根據loginToken 看能不查到當前token token有效期就1分鍾
		
		String tokenPassword=new String(token.getPassword());

		User user = accountManager.findUserByLoginNameOrEmail(token.getUsername());

		//user.getStandardLock()==1 
		if (user != null &&  user.getStatus().intValue()!=0 && !user.getLoginName().endsWith("@chacuo.net")) {
			 return new SimpleAuthenticationInfo(user.getLoginName(), user.getShaPassword() , getName());
		} else {
			return null;
		}
	}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:22,代碼來源:ShiroDbRealm.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
 * 認證回調函數,登錄時調用
 */
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authcToken) throws AuthenticationException {
	UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
	String accountName = token.getUsername();
	String password = new String(token.getPassword());

	// 用戶名密碼驗證		if (accountName != null && !"".equals(accountName)) {
		//UserService userService = BGDispatch.userService;
		User user = User.dao.findFirst(
				" select* from user where username= ? and password=?",
				accountName,password);

		if (user != null)
			return new SimpleAuthenticationInfo(new Principal(user),
					password, accountName);

	return null;
}
 
開發者ID:yaokwok,項目名稱:loveabc,代碼行數:22,代碼來源:MyShiroRealm.java

示例4: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  UsernamePasswordToken upToken = (UsernamePasswordToken) token;

  String password = new String(upToken.getPassword());
  String userId = upToken.getUsername();

  // username == password
  try {
    if (userId.endsWith(password) && userManager.getUser(userId) != null) {
      return new SimpleAuthenticationInfo(new SimplePrincipalCollection(token.getPrincipal(),
          this.getName()), userId);
    }
    else {
      throw new IncorrectCredentialsException("User [" + userId + "] bad credentials.");
    }
  }
  catch (UserNotFoundException e) {
    throw new UnknownAccountException("User [" + userId + "] not found.");
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:22,代碼來源:MockRealm.java

示例5: supports

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public boolean supports(AuthenticationToken token) {
	try {
		UsernamePasswordToken upt = (UsernamePasswordToken) token;
		String username = upt.getUsername();
		char[] password = upt.getPassword();
		List<SecurityUserEntity> lists = template.query(
				"select * from  security_user where username=?",
				new Object[] { username }, new SecurityUserEntity());
		if (lists != null && lists.size() > 0) {
			SecurityUserEntity entity = lists.get(0);
			byte[] keyBytes = entity.getKey();

			if (new String(password).equals(new String(Base64
					.decode(aesCipherService.decrypt(
							Base64.decode(entity.getPassword()), keyBytes)
							.toBase64())))) {
				return true;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return false;
}
 
開發者ID:luozhengjie,項目名稱:RLCMS,代碼行數:26,代碼來源:UserNamePasswordRealm.java

示例6: createAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
 * Method description
 * 
 * 
 * @param token
 * @param result
 * 
 * @return
 */
private AuthenticationInfo createAuthenticationInfo(
		UsernamePasswordToken token, AuthenticationResult result) {
	User user = result.getUser();
	Collection<String> groups = authenticate(
			new String(token.getPassword()), result);

	SimplePrincipalCollection collection = new SimplePrincipalCollection();

	/*
	 * the first (primary) principal should be a unique identifier
	 */
	collection.add(user.getId(), NAME);
	collection.add(user, NAME);
	collection.add(new GroupNames(groups), NAME);

	return new SimpleAuthenticationInfo(collection, token.getPassword());
}
 
開發者ID:litesolutions,項目名稱:scm-ssh-plugin,代碼行數:27,代碼來源:ScmPasswordRealm.java

示例7: getAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public AuthenticationInfo getAuthenticationInfo(final AuthenticationToken token) {
	UsernamePasswordToken userToken = (UsernamePasswordToken) token;
	String username = userToken.getUsername();
	char[] password = userToken.getPassword();
	
	if((username != null) && (!username.isEmpty()) && (password != null) && (password.length > 0)) {
		SimpleUser user = this.userService.getByUsernamePassword(username, new String(password));
		if (user != null) {
			AuthenticationInfo info = new SimpleAuthenticationInfo(user, password, this.getName());
			return info;
		}
	}

	return null;
}
 
開發者ID:lsjunior,項目名稱:shiro-cdi,代碼行數:17,代碼來源:SimpleRealm.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
        AuthenticationToken token) throws AuthenticationException {
    RegToken rtoken = null;
    if ( token instanceof UsernamePasswordToken ) {
        UsernamePasswordToken uptoken = (UsernamePasswordToken) token;
        rtoken = new RegToken(uptoken.getUsername(), new String(uptoken.getPassword()));
    } else if (token instanceof RegToken) {
        rtoken = (RegToken)token;
    } else {
        throw new IncorrectCredentialsException();
    }
    String id = (String)rtoken.getPrincipal();
    SaltedAuthenticationInfo info = getUserStore().checkUser(id);
    return info;
}
 
開發者ID:UKGovLD,項目名稱:registry-core,代碼行數:17,代碼來源:RegRealm.java

示例9: doCredentialsMatch

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    UsernamePasswordToken usernamePasswordToken= (UsernamePasswordToken) token;
    String password=new String(usernamePasswordToken.getPassword());
    SimpleHash hash=new SimpleHash("md5",password,"1997password",3);

    String dbPassword= (String) info.getCredentials();
    return this.equals(hash.toString(),dbPassword);
}
 
開發者ID:fuyunwang,項目名稱:SpringBootShiro,代碼行數:10,代碼來源:CredentialMatcher.java

示例10: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
		throws AuthenticationException {
	UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("countSql", 0);
	params.put("enable", 1);
	params.put("account", token.getUsername());
	Page<?> pageInfo = sysUserService.query(params);
	if (pageInfo.getTotal() == 1) {
		SysUser user = (SysUser) pageInfo.getRecords().get(0);
		StringBuilder sb = new StringBuilder(100);
		for (int i = 0; i < token.getPassword().length; i++) {
			sb.append(token.getPassword()[i]);
		}
		if (user.getPassword().equals(sb.toString())) {
			WebUtil.saveCurrentUser(user.getId());
			saveSession(user.getAccount());
			AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(),
					user.getUserName());
			return authcInfo;
		}
		logger.warn("USER [{}] PASSWORD IS WRONG: {}", token.getUsername(), sb.toString());
		return null;
	} else {
		logger.warn("No user: {}", token.getUsername());
		return null;
	}
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:29,代碼來源:Realm.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
 * 登錄認證
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken arg0) throws AuthenticationException {
	UsernamePasswordToken token = (UsernamePasswordToken) arg0;
	// String roncooNo = token.getUsername();
	// String password = token.getPassword().toString();
	
	SecurityUtils.getSubject().getSession().setAttribute(Constants.Session.USER, sysUserDao.getByUserPhone(ConfUtil.USER));
	return new SimpleAuthenticationInfo(token, token.getPassword(), getName());
}
 
開發者ID:roncoo,項目名稱:roncoo-jui-springboot,代碼行數:13,代碼來源:ShiroConfiguration.java

示例12: doCredentialsMatch

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    if (token instanceof UsernamePasswordToken) {
        UsernamePasswordToken upToken = (UsernamePasswordToken) token;

        if (DEFAULT_WEB_USERNAME.equals(upToken.getUsername())) {
            return true;
        }

        // Password sent via HTTP.
        char[] attemptPassword = upToken.getPassword();
        // Password from user collection in DB.
        byte[] userPassword = getCredentials(info);
        // Salt from user collection in DB.
        byte[] userSalt = getSalt(info);

        try {
            if (attemptPassword == null || userPassword == null || userSalt == null || attemptPassword.length == 0
                || userPassword.length == 0 || userSalt.length == 0) {
                return false;
            }

            return Passwords.authenticate(String.valueOf(attemptPassword), userPassword, getSalt(userSalt));
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    } else {
        throw new RuntimeException(
            "The AuthenticationToken must be of type 'org.apache.shiro.authc.UsernamePasswordToken'");
    }
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:32,代碼來源:DefaultCredentialsMatcher.java

示例13: doCredentialsMatch

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    UsernamePasswordToken credentials = (UsernamePasswordToken) token;
    Password password = new Password(credentials.getPassword());
    UsernamePasswordCredential credential = new UsernamePasswordCredential(credentials.getUsername(), password);
    CredentialValidationResult validationResult = identityStore.validate(credential);

    boolean result = validationResult.getStatus().equals(CredentialValidationResult.Status.VALID);
    if (result) {
        ExternalPasswordAuthenticationInfo authenticationInfo = (ExternalPasswordAuthenticationInfo) info;
        authenticationInfo.addUserInfo(CALLER_GROUPS, createUserInfo(validationResult.getCallerGroups()));
        authenticationInfo.addUserInfo(CALLER_ROLES, createUserInfo(validationResult.getCallerRoles()));
    }
    return result;
}
 
開發者ID:rdebusscher,項目名稱:octopus-jsr375,代碼行數:16,代碼來源:IdentityStoreMatcher.java

示例14: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  // only allow jcool/jcool
  UsernamePasswordToken userpass = (UsernamePasswordToken) token;
  if ("jcool".equals(userpass.getUsername()) && "jcool".equals(new String(userpass.getPassword()))) {
    return new SimpleAuthenticationInfo(userpass.getUsername(), new String(userpass.getPassword()), this.getName());
  }

  return null;
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:11,代碼來源:MockRealmB.java

示例15: doGetAuthenticationInfo

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
    throws AuthenticationException
{
  // only allow jcoder/jcoder

  UsernamePasswordToken userpass = (UsernamePasswordToken) token;
  if ("jcoder".equals(userpass.getUsername()) && "jcoder".equals(new String(userpass.getPassword()))) {
    return new SimpleAuthenticationInfo(userpass.getUsername(), new String(userpass.getPassword()), this.getName());
  }

  return null;
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:14,代碼來源:MockRealmA.java


注:本文中的org.apache.shiro.authc.UsernamePasswordToken.getPassword方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。