use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.
the class SimpleSecurityManager method authenticate.
private boolean authenticate(SecurityContext context, Subject subject) {
SecurityContextUtil util = context.getUtil();
SubjectInfo subjectInfo = getSubjectInfo(context);
if (subject == null) {
subject = new Subject();
}
Principal principal = util.getUserPrincipal();
Principal auditPrincipal = principal;
Object credential = util.getCredential();
Identity unauthenticatedIdentity = null;
boolean authenticated = false;
if (principal == null) {
unauthenticatedIdentity = getUnauthenticatedIdentity();
subjectInfo.addIdentity(unauthenticatedIdentity);
auditPrincipal = unauthenticatedIdentity.asPrincipal();
subject.getPrincipals().add(auditPrincipal);
authenticated = true;
} else {
subject.getPrincipals().add(principal);
}
if (authenticated == false) {
AuthenticationManager authenticationManager = context.getAuthenticationManager();
authenticated = authenticationManager.isValid(principal, credential, subject);
}
if (authenticated == true) {
subjectInfo.setAuthenticatedSubject(subject);
}
AuditManager auditManager = context.getAuditManager();
if (auditManager != null) {
audit(authenticated ? AuditLevel.SUCCESS : AuditLevel.FAILURE, auditManager, auditPrincipal);
}
return authenticated;
}
use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.
the class JNDIBasedSecurityManagement method getAuthenticationManager.
/** {@inheritDoc} */
public AuthenticationManager getAuthenticationManager(String securityDomain) {
AuthenticationManager am = null;
try {
am = authMgrMap.get(securityDomain);
if (am == null) {
am = (AuthenticationManager) lookUpJNDI(securityDomain + "/authenticationMgr");
authMgrMap.put(securityDomain, am);
}
} catch (Exception e) {
SecurityLogger.ROOT_LOGGER.tracef(e, "Exception getting AuthenticationManager for domain=%s", securityDomain);
}
return am;
}
use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.
the class UndertowDeploymentInfoService method handleAuthManagerLogout.
private void handleAuthManagerLogout(DeploymentInfo deploymentInfo, JBossWebMetaData mergedMetaData) {
if (securityDomain == null) {
return;
}
AuthenticationManager manager = securityDomainContextValue.getValue().getAuthenticationManager();
deploymentInfo.addNotificationReceiver(new LogoutNotificationReceiver(manager, securityDomain));
if (mergedMetaData.isFlushOnSessionInvalidation()) {
LogoutSessionListener listener = new LogoutSessionListener(manager);
deploymentInfo.addListener(Servlets.listener(LogoutSessionListener.class, new ImmediateInstanceFactory<EventListener>(listener)));
}
}
use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.
the class UndertowDeploymentInfoService method stop.
@Override
public synchronized void stop(final StopContext stopContext) {
IoUtils.safeClose(this.deploymentInfo.getResourceManager());
if (securityDomain != null && securityFunction.getOptionalValue() == null) {
AuthenticationManager authManager = securityDomainContextValue.getValue().getAuthenticationManager();
if (authManager != null && authManager instanceof JBossCachedAuthenticationManager) {
((JBossCachedAuthenticationManager) authManager).releaseModuleEntries(module.getClassLoader());
}
}
this.deploymentInfo.setConfidentialPortManager(null);
this.deploymentInfo = null;
if (registration != null) {
registration.cancel();
}
}
use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.
the class JAASIdentityManagerImpl method verifyCredential.
private Account verifyCredential(final AccountImpl account, final Object credential) {
final AuthenticationManager authenticationManager = securityDomainContext.getAuthenticationManager();
final AuthorizationManager authorizationManager = securityDomainContext.getAuthorizationManager();
final SecurityContext sc = SecurityActions.getSecurityContext();
Principal incomingPrincipal = account.getOriginalPrincipal();
Subject subject = new Subject();
try {
boolean isValid = authenticationManager.isValid(incomingPrincipal, credential, subject);
if (isValid) {
UndertowLogger.ROOT_LOGGER.tracef("User: %s is authenticated", incomingPrincipal);
if (sc == null) {
throw UndertowLogger.ROOT_LOGGER.noSecurityContext();
}
Principal userPrincipal = getPrincipal(subject);
sc.getUtil().createSubjectInfo(incomingPrincipal, credential, subject);
SecurityContextCallbackHandler scb = new SecurityContextCallbackHandler(sc);
RoleGroup roles = authorizationManager.getSubjectRoles(subject, scb);
Set<String> roleSet = new HashSet<>();
for (Role role : roles.getRoles()) {
roleSet.add(role.getRoleName());
}
return new AccountImpl(userPrincipal, roleSet, credential, account.getOriginalPrincipal());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
Aggregations