本文整理匯總了Java中org.apache.shiro.authc.UsernamePasswordToken.getCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordToken.getCredentials方法的具體用法?Java UsernamePasswordToken.getCredentials怎麽用?Java UsernamePasswordToken.getCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.authc.UsernamePasswordToken
的用法示例。
在下文中一共展示了UsernamePasswordToken.getCredentials方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
throws AuthenticationException {
UsernamePasswordToken userToken = (UsernamePasswordToken) token;
UnixUser user;
try {
user = (new PAM(this.getService()))
.authenticate(userToken.getUsername(), new String(userToken.getPassword()));
} catch (PAMException e) {
throw new AuthenticationException("Authentication failed for PAM.", e);
}
return new SimpleAuthenticationInfo(
new UserPrincipal(user),
userToken.getCredentials(),
getName());
}
示例2: 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());
}
示例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;
}
示例5: doGetAuthenticationInfo
import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken)
throws AuthenticationException {
if (!(authenticationToken instanceof UsernamePasswordToken)) {
throw new UnsupportedTokenException("Token of type " + authenticationToken.getClass().getName()
+ " is not supported. A " + UsernamePasswordToken.class.getName() + " is required.");
}
UsernamePasswordToken userPass = (UsernamePasswordToken) authenticationToken;
String token = new String(userPass.getPassword());
if (token.isEmpty()) {
LOGGER.debug(GITLAB_MSG + "token for {} is empty", userPass.getUsername());
return null;
}
try {
LOGGER.debug(GITLAB_MSG + "authenticating {}", userPass.getUsername());
LOGGER.debug(GITLAB_MSG + "null? " + (gitlab == null));
LOGGER.debug(GITLAB_MSG + "null? " + (gitlab.getRestClient() == null));
GitlabUser gitlabUser = gitlab.getRestClient().getUser(userPass.getUsername(), token);
User user = gitlabUser.toUser();
if (user.getUserId() == null || user.getUserId().isEmpty()) {
LOGGER.debug(GITLAB_MSG + "authentication failed {}", user);
throw new AuthenticationException(DEFAULT_MESSAGE + " for " + userPass.getUsername());
}
LOGGER.debug(GITLAB_MSG + "successfully authenticated {}", userPass.getUsername());
return new SimpleAuthenticationInfo(gitlabUser /*userPass.getPrincipal()*/,
userPass.getCredentials(), getName());
} catch (Exception e) {
LOGGER.debug(GITLAB_MSG + "authentication failed {}", userPass.getUsername());
throw new AuthenticationException(DEFAULT_MESSAGE, e);
}
}