本文整理匯總了Java中org.apache.shiro.authc.UsernamePasswordToken.getPrincipal方法的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordToken.getPrincipal方法的具體用法?Java UsernamePasswordToken.getPrincipal怎麽用?Java UsernamePasswordToken.getPrincipal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authc.UsernamePasswordToken
的用法示例。
在下文中一共展示了UsernamePasswordToken.getPrincipal方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
if (!"password".equals(new String(upToken.getPassword()))) {
throw new AuthenticationException("Invalid password for user: " + upToken.getUsername());
}
return new SimpleAuthenticationInfo(upToken.getPrincipal(), upToken.getCredentials(), getName());
}
示例2: authenticateUser
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) {
boolean authenticated = currentUser.isAuthenticated();
boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal());
LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser);
if (!authenticated || !sameUser) {
UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(), securityToken.getPassword());
if (policy.isAlwaysReauthenticate()) {
token.setRememberMe(false);
} else {
token.setRememberMe(true);
}
try {
currentUser.login(token);
LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal());
} catch (UnknownAccountException uae) {
throw new UnknownAccountException("Authentication Failed. There is no user with username of " + token.getPrincipal(), uae.getCause());
} catch (IncorrectCredentialsException ice) {
throw new IncorrectCredentialsException("Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!", ice.getCause());
} catch (LockedAccountException lae) {
throw new LockedAccountException("Authentication Failed. The account for username " + token.getPrincipal() + " is locked."
+ "Please contact your administrator to unlock it.", lae.getCause());
} catch (AuthenticationException ae) {
throw new AuthenticationException("Authentication Failed.", ae.getCause());
}
}
}
示例3: copy
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
// this is the only way to trick the superclass into believing subject is always authenticated
UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), "Permissive");
subjectContext.setAuthenticated(true);
subjectContext.setAuthenticationToken(token);
subjectContext.setAuthenticationInfo(info);
return subjectContext;
}
示例4: copy
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
// this is the only way to trick the superclass into believing subject is always authenticated
UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(),
token.getCredentials(),
"Permissive");
subjectContext.setAuthenticated(true);
subjectContext.setAuthenticationToken(token);
subjectContext.setAuthenticationInfo(info);
return subjectContext;
}