本文整理汇总了Java中io.undertow.security.api.SecurityContext.getAuthenticatedAccount方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContext.getAuthenticatedAccount方法的具体用法?Java SecurityContext.getAuthenticatedAccount怎么用?Java SecurityContext.getAuthenticatedAccount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.security.api.SecurityContext
的用法示例。
在下文中一共展示了SecurityContext.getAuthenticatedAccount方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) {
SecurityContext sc = exchange.getSecurityContext();
Account account = sc.getAuthenticatedAccount();
if (account != null) {
try (SingleSignOn sso = manager.createSingleSignOn(account, sc.getMechanismName())) {
Session session = getSession(exchange);
registerSessionIfRequired(sso, session);
exchange.getResponseCookies().put(cookieName, new CookieImpl(cookieName, sso.getId()).setHttpOnly(httpOnly).setSecure(secure).setDomain(domain).setPath(path));
}
}
return factory.create();
}
示例2: isUserInRole
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public boolean isUserInRole(final String role) {
if (role == null) {
return false;
}
//according to the servlet spec this aways returns false
if (role.equals("*")) {
return false;
}
SecurityContext sc = exchange.getSecurityContext();
Account account = sc.getAuthenticatedAccount();
if (account == null) {
return false;
}
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (role.equals("**")) {
Set<String> roles = servletRequestContext.getDeployment().getDeploymentInfo().getSecurityRoles();
if (!roles.contains("**")) {
return true;
}
}
final ServletChain servlet = servletRequestContext.getCurrentServlet();
final Deployment deployment = servletContext.getDeployment();
final AuthorizationManager authorizationManager = deployment.getDeploymentInfo().getAuthorizationManager();
return authorizationManager.isUserInRole(role, account, servlet.getManagedServlet().getServletInfo(), this, deployment);
}
示例3: getUserPrincipal
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public Principal getUserPrincipal() {
SecurityContext securityContext = exchange.getSecurityContext();
Principal result = null;
Account account = null;
if (securityContext != null && (account = securityContext.getAuthenticatedAccount()) != null) {
result = account.getPrincipal();
}
return result;
}
示例4: getUserPrincipal
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public Principal getUserPrincipal() {
SecurityContext sc = exchange.getSecurityContext();
if(sc == null) {
return null;
}
Account authenticatedAccount = sc.getAuthenticatedAccount();
if(authenticatedAccount == null) {
return null;
}
return authenticatedAccount.getPrincipal();
}
示例5: isUserInRole
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
@Override
public boolean isUserInRole(String role) {
SecurityContext sc = exchange.getSecurityContext();
if(sc == null) {
return false;
}
Account authenticatedAccount = sc.getAuthenticatedAccount();
if(authenticatedAccount == null) {
return false;
}
return authenticatedAccount.getRoles().contains(role);
}
示例6: 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;
}
示例7: getUndertowUser
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
private String getUndertowUser(final HttpServerExchange exchange) {
SecurityContext context = exchange.getSecurityContext();
if (context != null) {
Account account = context.getAuthenticatedAccount();
if (account != null) {
// An account must always return a Principal otherwise it is not an Account.
return account.getPrincipal().getName();
}
}
return null;
}
示例8: getAccount
import io.undertow.security.api.SecurityContext; //导入方法依赖的package包/类
private static Pac4jAccount getAccount(final HttpServerExchange exchange) {
final SecurityContext securityContext = exchange.getSecurityContext();
if (securityContext != null) {
final Account account = securityContext.getAuthenticatedAccount();
if (account instanceof Pac4jAccount) {
return (Pac4jAccount) account;
}
}
return null;
}