本文整理匯總了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;
}
}
示例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;
}
}
示例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;
}
示例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.");
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}