本文整理汇总了Java中javax.security.enterprise.credential.Credential类的典型用法代码示例。如果您正苦于以下问题:Java Credential类的具体用法?Java Credential怎么用?Java Credential使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Credential类属于javax.security.enterprise.credential包,在下文中一共展示了Credential类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: login
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
Credential credential = new UsernamePasswordCredential(username, new Password(password));
AuthenticationStatus status = securityContext.authenticate(
getRequest(context),
getResponse(context),
withParams()
.credential(credential)
.newAuthentication(!continued)
.rememberMe(rememberMe)
);
LOG.info("authentication result:" + status);
if (status.equals(SEND_CONTINUE)) {
// Authentication mechanism has send a redirect, should not
// send anything to response from JSF now.
context.responseComplete();
} else if (status.equals(SEND_FAILURE)) {
addError(context, "Authentication failed");
}
}
示例2: login
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
public void login() {
Credential credential = new UsernamePasswordCredential(username, new Password(password));
AuthenticationStatus status = securityContext.authenticate(
getRequestFrom(facesContext),
getResponseFrom(facesContext),
withParams().credential(credential));
if (status.equals(SEND_CONTINUE)) {
facesContext.responseComplete();
} else if (status.equals(SEND_FAILURE)) {
addError(facesContext, "Authentication failed");
}
}
示例3: validate
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
if (credential instanceof TokenResponseCredential) {
TokenResponseCredential tokenCredential = (TokenResponseCredential) credential;
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/userinfo");
OAuth20Service service = tokenCredential.getService();
OAuth2AccessToken token = tokenCredential.getTokenResponse();
service.signRequest(token, request);
try {
Response oResp = service.execute(request);
String body = oResp.getBody();
OAuth2User oAuth2User = jsonProcessor.extractUserInfo(body);
return new CredentialValidationResult(oAuth2User);
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace(); // FIXME
}
}
return CredentialValidationResult.NOT_VALIDATED_RESULT;
}
示例4: validate
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
CredentialValidationResult result;
if (credential instanceof UsernamePasswordCredential) {
UsernamePasswordCredential usernamePassword = (UsernamePasswordCredential) credential;
result = users.findByUsername(usernamePassword.getCaller())
.map(
u -> passwordHash.matches(new String(usernamePassword.getPassword().getValue()), u.getPassword())
? new CredentialValidationResult(usernamePassword.getCaller(), u.getAuthorities())
: INVALID_RESULT
)
.orElse(INVALID_RESULT);
} else {
result = NOT_VALIDATED_RESULT;
}
return result;
}
示例5: login
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
Credential credential = new UsernamePasswordCredential(username, new Password(password));
AuthenticationStatus status = securityContext.authenticate(
getRequest(context),
getResponse(context),
withParams()
.credential(credential));
LOG.info("authentication result:" + status);
if (status.equals(SEND_CONTINUE)) {
// Authentication mechanism has send a redirect, should not
// send anything to response from JSF now.
context.responseComplete();
} else if (status.equals(SEND_FAILURE)) {
addError(context, "Authentication failed");
}
}
示例6: login
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
public void login() {
FacesContext context = FacesContext.getCurrentInstance();
Credential credential = new UsernamePasswordCredential(username, new Password(password));
AuthenticationStatus status = securityContext.authenticate(
getRequest(context),
getResponse(context),
withParams()
.credential(credential));
LOG.log(Level.INFO, "authentication result:{0}", status);
if (status.equals(SEND_CONTINUE)) {
// Authentication mechanism has send a redirect, should not
// send anything to response from JSF now.
context.responseComplete();
} else if (status.equals(SEND_FAILURE)) {
addError(context, "Authentication failed");
}
}
示例7: validateRequest
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
@Override
public AuthenticationStatus validateRequest(
HttpServletRequest request,
HttpServletResponse response,
HttpMessageContext context) throws AuthenticationException {
Credential credential = context.getAuthParameters().getCredential();
if (credential != null) {
return context.notifyContainerAboutLogin(identityStore.validate(credential));
} else {
return context.doNothing();
}
}
示例8: validate
import javax.security.enterprise.credential.Credential; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
UsernamePasswordCredential user = (UsernamePasswordCredential) credential;
if (user.getCaller().equalsIgnoreCase("Duke") && user.getPasswordAsString().equalsIgnoreCase("Dance")) {
return new CredentialValidationResult("Duke",new HashSet<>(asList("foo", "bar")));
}
return INVALID_RESULT;
}