本文整理匯總了Java中org.apache.shiro.authc.UsernamePasswordToken.getUsername方法的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordToken.getUsername方法的具體用法?Java UsernamePasswordToken.getUsername怎麽用?Java UsernamePasswordToken.getUsername使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authc.UsernamePasswordToken
的用法示例。
在下文中一共展示了UsernamePasswordToken.getUsername方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// identify account to log to
UsernamePasswordToken userPassToken = (UsernamePasswordToken) token;
final String username = userPassToken.getUsername();
if (username == null) {
return null;
}
// read password hash and salt from db
final User user = UserDAO.getUser(username);
if (user == null) {
return null;
}
// return salted credentials
SaltedAuthenticationInfo info = new SaltedAuthInfo(username, user.getPassword(), user.getSalt());
return info;
}
示例2: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
/* if (Strings.isBlank(upToken.getCaptcha()))
throw new AuthenticationException("驗證碼不能為空");
String _captcha = Strings.sBlank(SecurityUtils.getSubject().getSession(true).getAttribute(Toolkit.captcha_attr));
if (!upToken.getCaptcha().equalsIgnoreCase(_captcha))
throw new AuthenticationException("驗證碼錯誤");*/
User user = dao().fetch(User.class, Cnd.where("name", "=", upToken.getUsername()));
if (user == null)
return null;
if (user.isLocked())
throw new LockedAccountException("Account [" + upToken.getUsername() + "] is locked.");
ByteSource salt = ByteSource.Util.bytes(user.getSalt());
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName());
info.setCredentialsSalt(salt);
return info;
}
示例3: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
final AuthenticationToken token)
throws AuthenticationException {
final UsernamePasswordToken credentials = (UsernamePasswordToken) token;
final String userName = credentials.getUsername();
if (userName == null) {
throw new UnknownAccountException("userName not provided");
}
Account account = accountRepository.findByLoginName(userName);
if (account == null) {
throw new UnknownAccountException("Account does not exist");
}
return new SimpleAuthenticationInfo(userName, account.getPassword().toCharArray(),
ByteSource.Util.bytes(userName), getName());
}
示例4: 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;
}
示例5: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的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!");
}
示例6: 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.");
}
}
示例7: 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;
}
示例8: getAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
UsernamePasswordToken upt = (UsernamePasswordToken) token;
String username = upt.getUsername();
list = template
.queryForList(
"select srp.permission as permission from security_user_roles as sur , security_roles_permissions as srp where sur.username=? and srp.role_name = sur.role_name",
username);
} catch (Exception e) {
e.printStackTrace();
}
return new RLCMSAuthenticationInfo(this.getName(), list,
token.getCredentials());
}
示例9: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
*
* @param authenticationToken
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken)
throws AuthenticationException {
final UsernamePasswordToken token =
(UsernamePasswordToken) authenticationToken;
final User user = this.accountService
.findUserByUsername(token.getUsername());
if (user != null) {
return new SimpleAuthenticationInfo(
token.getUsername(), user.getPassword(), this.getName());
}
throw new IncorrectCredentialsException("Invalid user or password");
}
示例10: queryForAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
* Builds an {@link AuthenticationInfo} object by querying the active directory LDAP context for
* the specified username. This method binds to the LDAP server using the provided username
* and password - which if successful, indicates that the password is correct.
* <p/>
* This method can be overridden by subclasses to query the LDAP server in a more complex way.
*
* @param token the authentication token provided by the user.
* @param ldapContextFactory the factory used to build connections to the LDAP server.
* @return an {@link AuthenticationInfo} instance containing information retrieved from LDAP.
* @throws NamingException if any LDAP errors occur during the search.
*/
protected AuthenticationInfo queryForAuthenticationInfo(
AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
// Binds using the username and password provided by the user.
LdapContext ctx = null;
try {
String userPrincipalName = upToken.getUsername();
if (!isValidPrincipalName(userPrincipalName)) {
return null;
}
if (this.principalSuffix != null && userPrincipalName.indexOf('@') < 0) {
userPrincipalName = upToken.getUsername() + this.principalSuffix;
}
ctx = ldapContextFactory.getLdapContext(
userPrincipalName, upToken.getPassword());
} finally {
LdapUtils.closeContext(ctx);
}
return buildAuthenticationInfo(upToken.getUsername(), upToken.getPassword());
}
示例11: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
if (token instanceof UsernamePasswordToken) {
final UsernamePasswordToken upToken = (UsernamePasswordToken)token;
final String username = upToken.getUsername();
final UserStorage storage = UsersPlugin.getInstance().getStorage();
final DB db = storage.getTxMaker().makeTx();
try {
final User user = storage.getUserMap(db).get(username);
if (user == null) {
return null;
}
Hash hash = new Shiro1CryptFormat().parse(user.getHashedPassword());
return new UserInfo(user.getUsername(), hash);
} finally {
db.close();
}
}
return null;
}
示例12: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
final AuthenticationToken token)
throws AuthenticationException {
final UsernamePasswordToken credentials = (UsernamePasswordToken) token;
final String email = credentials.getUsername();
if (email == null) {
throw new UnknownAccountException("Email not provided");
}
final User user = userRepository.findByEmailAndActive(email, true);
if (user == null) {
throw new UnknownAccountException("Account does not exist");
}
return new SimpleAuthenticationInfo(email, user.getPassword().toCharArray(),
ByteSource.Util.bytes(email), getName());
}
示例13: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的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;
}
示例14: 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;
}
示例15: 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;
}