本文整理汇总了Java中io.undertow.security.api.SecurityContext.authenticationComplete方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContext.authenticationComplete方法的具体用法?Java SecurityContext.authenticationComplete怎么用?Java SecurityContext.authenticationComplete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.security.api.SecurityContext
的用法示例。
在下文中一共展示了SecurityContext.authenticationComplete方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runCached
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
public AuthenticationMechanismOutcome runCached(final HttpServerExchange exchange, final SecurityContext securityContext, final AuthenticatedSessionManager sessionManager) {
AuthenticatedSession authSession = sessionManager.lookupSession(exchange);
if (authSession != null) {
Account account = securityContext.getIdentityManager().verify(authSession.getAccount());
if (account != null) {
securityContext.authenticationComplete(account, authSession.getMechanism(), false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
sessionManager.clearSession(exchange);
// We know we had a previously authenticated account but for some reason the IdentityManager is no longer
// accepting it, we now
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
} else {
// It is possible an AuthenticatedSessionManager could have been available even if there was no chance of it
// loading a session.
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
}
示例2: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
String principal = exchange.getAttachment(EXTERNAL_PRINCIPAL);
if(principal == null) {
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
Account account = securityContext.getIdentityManager().verify(principal, ExternalCredential.INSTANCE);
if(account == null) {
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
String name = exchange.getAttachment(EXTERNAL_AUTHENTICATION_TYPE);
securityContext.authenticationComplete(account, name != null ? name: this.name, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
示例3: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange,
final SecurityContext securityContext) {
ServerConnection connection = exchange.getConnection();
NegotiationContext negContext = connection.getAttachment(NegotiationContext.ATTACHMENT_KEY);
if (negContext != null) {
exchange.putAttachment(NegotiationContext.ATTACHMENT_KEY, negContext);
if (negContext.isEstablished()) {
IdentityManager identityManager = securityContext.getIdentityManager();
final Account account = identityManager.verify(new GSSContextCredential(negContext.getGssContext()));
if (account != null) {
securityContext.authenticationComplete(account, name, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
List<String> authHeaders = exchange.getRequestHeaders().get(AUTHORIZATION);
if (authHeaders != null) {
for (String current : authHeaders) {
if (current.startsWith(NEGOTIATE_PREFIX)) {
String base64Challenge = current.substring(NEGOTIATE_PREFIX.length());
try {
ByteBuffer challenge = FlexBase64.decode(base64Challenge);
return runGSSAPI(exchange, challenge, securityContext);
} catch (IOException e) {
}
// By this point we had a header we should have been able to verify but for some reason
// it was not correctly structured.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
// No suitable header was found so authentication was not even attempted.
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例4: runFormAuth
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
public AuthenticationMechanismOutcome runFormAuth(final HttpServerExchange exchange, final SecurityContext securityContext) {
final FormDataParser parser = formParserFactory.createParser(exchange);
if (parser == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as no form parser is present");
// TODO - May need a better error signaling mechanism here to prevent repeated attempts.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
try {
final FormData data = parser.parseBlocking();
final FormData.FormValue jUsername = data.getFirst("j_username");
final FormData.FormValue jPassword = data.getFirst("j_password");
if (jUsername == null || jPassword == null) {
UndertowLogger.REQUEST_LOGGER.debug("Could not authenticate as username or password was not present in the posted result");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
final String userName = jUsername.getValue();
final String password = jPassword.getValue();
AuthenticationMechanismOutcome outcome = null;
PasswordCredential credential = new PasswordCredential(password.toCharArray());
try {
IdentityManager identityManager = securityContext.getIdentityManager();
Account account = identityManager.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, name, true);
outcome = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
}
} finally {
if (outcome == AuthenticationMechanismOutcome.AUTHENTICATED) {
handleRedirectBack(exchange);
exchange.endExchange();
}
return outcome != null ? outcome : AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
public AuthenticationMechanismOutcome authenticate(final HttpServerExchange exchange, final SecurityContext securityContext) {
SSLSessionInfo sslSession = exchange.getConnection().getSslSessionInfo();
if (sslSession != null) {
try {
Certificate[] clientCerts = getPeerCertificates(exchange, sslSession, securityContext);
if (clientCerts[0] instanceof X509Certificate) {
Credential credential = new X509CertificateCredential((X509Certificate) clientCerts[0]);
IdentityManager idm = securityContext.getIdentityManager();
Account account = idm.verify(credential);
if (account != null) {
securityContext.authenticationComplete(account, name, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
}
} catch (SSLPeerUnverifiedException e) {
// No action - this mechanism can not attempt authentication without peer certificates so allow it to drop out
// to NOT_ATTEMPTED.
}
}
/*
* For ClientCert we do not have a concept of a failed authentication, if the client did use a key then it was deemed
* acceptable for the connection to be established, this mechanism then just 'attempts' to use it for authentication but
* does not mandate success.
*/
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例6: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(
HttpServerExchange exchange, SecurityContext securityContext) {
System.err.println("in authenticate");
securityContext.authenticationComplete(account, "FORM", false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
示例7: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
Account account = securityContext.getAuthenticatedAccount();
if(account != null) {
if(logger.isDebugEnabled()) {
logger.debug("User {} already logged in - nothing to do", account.getPrincipal().getName());
}
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
try {
HeaderValues header = authorizationHeader(exchange);
if(header == null) {
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
String authorization = header.getFirst();
byte[] bytes = authorizationBytes(securityContext, authorization);
String[] credentials = authorizationCredentials(securityContext, bytes);
account = verify(credentials, securityContext.getIdentityManager()).orElseThrow(
() -> new AuthenticationException(AuthenticationMechanismOutcome.NOT_AUTHENTICATED,
"Authentication failed to log the user"));
} catch (AuthenticationException e) {
securityContext.authenticationFailed(e.getMessage(), MECHANISM_NAME);
return e.outcome;
}
securityContext.authenticationComplete(account, MECHANISM_NAME, !stateless);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
示例8: authenticationComplete
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
/**
* @see org.wildfly.security.http.HttpExchangeSpi#authenticationComplete(org.wildfly.security.auth.spi.AuthenticatedRealmIdentity, java.lang.String)
*/
@Override
public void authenticationComplete(SecurityIdentity securityIdentity, String mechanismName) {
SecurityContext securityContext = httpServerExchange.getSecurityContext();
if (securityContext != null) {
securityContext.authenticationComplete(new ElytronAccount(securityIdentity), mechanismName, false);
}
}
示例9: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext context) {
Principal user = new RealmUser(ANONYMOUS_USER);
Subject subject = new Subject();
subject.getPrincipals().add(user);
SocketAddress address = exchange.getConnection().getPeerAddress();
if (address instanceof InetSocketAddress) {
subject.getPrincipals().add(new InetAddressPrincipal(((InetSocketAddress) address).getAddress()));
}
context.authenticationComplete(new RealmIdentityAccount(subject, user), ANONYMOUS_MECH, false);
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
示例10: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
Cookie cookie = exchange.getRequestCookies().get(cookieName);
if (cookie != null) {
final String ssoId = cookie.getValue();
try (SingleSignOn sso = this.manager.findSingleSignOn(ssoId)) {
if (sso != null) {
Account verified = securityContext.getIdentityManager().verify(sso.getAccount());
if (verified == null) {
//we return not attempted here to allow other mechanisms to proceed as normal
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
final Session session = getSession(exchange);
registerSessionIfRequired(sso, session);
securityContext.authenticationComplete(verified, sso.getMechanismName(), false);
securityContext.registerNotificationReceiver(new NotificationReceiver() {
@Override
public void handleNotification(SecurityNotification notification) {
if (notification.getEventType() == SecurityNotification.EventType.LOGGED_OUT) {
manager.removeSingleSignOn(ssoId);
}
}
});
return AuthenticationMechanismOutcome.AUTHENTICATED;
}
}
clearSsoCookie(exchange);
}
exchange.addResponseWrapper(responseListener);
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例11: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
/**
* @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
*/
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
List<String> authHeaders = exchange.getRequestHeaders().get(AUTHORIZATION);
if (authHeaders != null) {
for (String current : authHeaders) {
if (current.startsWith(BASIC_PREFIX)) {
String base64Challenge = current.substring(PREFIX_LENGTH);
String plainChallenge = null;
try {
ByteBuffer decode = FlexBase64.decode(base64Challenge);
plainChallenge = new String(decode.array(), decode.arrayOffset(), decode.limit(), UTF_8);
} catch (IOException e) {
}
int colonPos;
if (plainChallenge != null && (colonPos = plainChallenge.indexOf(COLON)) > -1) {
String userName = plainChallenge.substring(0, colonPos);
char[] password = plainChallenge.substring(colonPos + 1).toCharArray();
IdentityManager idm = securityContext.getIdentityManager();
PasswordCredential credential = new PasswordCredential(password);
try {
final AuthenticationMechanismOutcome result;
Account account = idm.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, name, false);
result = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
securityContext.authenticationFailed(MESSAGES.authenticationFailed(userName), name);
result = AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
return result;
} finally {
clear(password);
}
}
// By this point we had a header we should have been able to verify but for some reason
// it was not correctly structured.
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
// No suitable header has been found in this request,
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例12: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
/**
* Extract the Authorization header and validate the bearer token if it exists. If it does, and is validated, this
* builds the org.jboss.security.SecurityContext authenticated Subject that drives the container APIs as well as
* the authorization layers.
*
* @param exchange - the http request exchange object
* @param securityContext - the current security context that
* @return one of AUTHENTICATED, NOT_AUTHENTICATED or NOT_ATTEMPTED depending on the header and authentication outcome.
*/
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
List<String> authHeaders = exchange.getRequestHeaders().get(AUTHORIZATION);
if (authHeaders != null) {
String bearerToken = null;
for (String current : authHeaders) {
if (current.toLowerCase(Locale.ENGLISH).startsWith("bearer ")) {
bearerToken = current.substring(7);
if (UndertowLogger.SECURITY_LOGGER.isTraceEnabled()) {
UndertowLogger.SECURITY_LOGGER.tracef("Bearer token: %s", bearerToken);
}
try {
identityManager = securityContext.getIdentityManager();
JWTCredential credential = new JWTCredential(bearerToken, authContextInfo);
if (UndertowLogger.SECURITY_LOGGER.isTraceEnabled()) {
UndertowLogger.SECURITY_LOGGER.tracef("Bearer token: %s", bearerToken);
}
// Install the JWT principal as the caller
Account account = identityManager.verify(credential.getName(), credential);
if (account != null) {
JsonWebToken jwtPrincipal = (JsonWebToken) account.getPrincipal();
MPJWTProducer.setJWTPrincipal(jwtPrincipal);
JWTAccount jwtAccount = new JWTAccount(jwtPrincipal, account);
securityContext.authenticationComplete(jwtAccount, "MP-JWT", false);
// Workaround authenticated JsonWebToken not being installed as user principal
// https://issues.jboss.org/browse/WFLY-9212
org.jboss.security.SecurityContext jbSC = SecurityContextAssociation.getSecurityContext();
Subject subject = jbSC.getUtil().getSubject();
jbSC.getUtil().createSubjectInfo(jwtPrincipal, bearerToken, subject);
RoleGroup roles = extract(subject);
jbSC.getUtil().setRoles(roles);
UndertowLogger.SECURITY_LOGGER.debugf("Authenticated caller(%s) for path(%s) with roles: %s",
credential.getName(), exchange.getRequestPath(), account.getRoles());
return AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
UndertowLogger.SECURITY_LOGGER.info("Failed to authenticate JWT bearer token");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
} catch (Exception e) {
UndertowLogger.SECURITY_LOGGER.infof(e, "Failed to validate JWT bearer token");
return AuthenticationMechanismOutcome.NOT_AUTHENTICATED;
}
}
}
}
// No suitable header has been found in this request,
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
示例13: authenticate
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public AuthenticationMechanismOutcome authenticate(HttpServerExchange exchange, SecurityContext securityContext) {
List<String> authHeaders = exchange.getRequestHeaders().get(AUTHORIZATION);
if (authHeaders != null) {
for (String current : authHeaders) {
if (current.startsWith(BASIC_PREFIX)) {
String base64Challenge = current.substring(PREFIX_LENGTH);
String plainChallenge = null;
try {
ByteBuffer decode = FlexBase64.decode(base64Challenge);
plainChallenge = new String(decode.array(), decode.arrayOffset(), decode.limit(), UTF_8);
} catch (IOException e) {
}
int colonPos;
if (plainChallenge != null && (colonPos = plainChallenge.indexOf(COLON)) > -1) {
String userName = plainChallenge.substring(0, colonPos);
char[] password = plainChallenge.substring(colonPos + 1).toCharArray();
// this is where the token cache comes into play
IdentityManager idm = AuthTokenIdentityManager.getInstance();
PasswordCredential credential = new PasswordCredential(password);
try {
final AuthenticationMechanismOutcome result;
Account account = idm.verify(userName, credential);
if (account != null) {
securityContext.authenticationComplete(account, mechanismName, false);
result = AuthenticationMechanismOutcome.AUTHENTICATED;
} else {
result = AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
return result;
} finally {
clear(password);
}
}
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}
}
}
return AuthenticationMechanismOutcome.NOT_ATTEMPTED;
}