use of ddf.security.impl.SubjectImpl in project ddf by codice.
the class SecurityManagerImpl method getSubject.
/**
* Creates a new subject based on an incoming AuthenticationToken
*
* @param token AuthenticationToken that should be used to authenticate the user and use as the
* basis for the new subject.
* @return new subject
* @throws SecurityServiceException
*/
private Subject getSubject(AuthenticationToken token) throws SecurityServiceException {
if (token.getCredentials() == null) {
throw new SecurityServiceException("CANNOT AUTHENTICATE USER: Authentication token did not contain any credentials. " + "This is generally due to an error on the authentication server.");
}
AuthenticationInfo info = internalManager.authenticate(token);
Collection<SecurityAssertion> securityAssertions = info.getPrincipals().byType(SecurityAssertion.class);
Iterator<SecurityAssertion> iterator = securityAssertions.iterator();
boolean userAuth = false;
while (iterator.hasNext()) {
SecurityAssertion assertion = iterator.next();
if (SecurityAssertion.IDP_AUTH_WEIGHT == assertion.getWeight() || SecurityAssertion.LOCAL_AUTH_WEIGHT == assertion.getWeight()) {
userAuth = true;
}
}
try {
return new SubjectImpl(info.getPrincipals(), userAuth, new SimpleSession(UUID.randomUUID().toString()), internalManager);
} catch (Exception e) {
throw new SecurityServiceException("Could not create a new subject", e);
}
}
use of ddf.security.impl.SubjectImpl in project ddf by codice.
the class SecurityManagerImpl method getSubject.
@Override
public Subject getSubject(Object token) throws SecurityServiceException {
AuthenticationToken authenticationToken = null;
if (token instanceof SessionToken) {
SimpleSession session = new SimpleSession();
session.setId((String) ((SessionToken) token).getCredentials());
return new SubjectImpl(((PrincipalCollection) ((SessionToken) token).getPrincipal()), true, session, internalManager);
} else if (token instanceof AuthenticationToken) {
authenticationToken = (AuthenticationToken) token;
}
if (authenticationToken != null) {
Subject subject = getSubject(authenticationToken);
securityLogger.audit("Logged in", subject);
return subject;
} else {
throw new SecurityServiceException("Incoming token object NOT supported by security manager implementation. Currently supported types are AuthenticationToken and SecurityToken");
}
}
use of ddf.security.impl.SubjectImpl in project ddf by codice.
the class LoginFilterTest method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
principalHolder = new PrincipalHolder();
principalHolder.setPrincipals(principalCollection);
loginFilter = new LoginFilter();
loginFilter.setSecurityManager(securityManagerMock);
loginFilter.setSessionFactory(sessionFactory);
loginFilter.setContextPolicyManager(contextPolicyManager);
loginFilter.init();
subject = new SubjectImpl(principalCollectionMock, true, null, mock(org.apache.shiro.mgt.SecurityManager.class));
when(securityAssertionMock.getToken()).thenReturn(goodSecurityTokenMock);
when(principalCollectionMock.byType(SecurityAssertion.class)).thenReturn(Collections.singletonList(securityAssertionMock));
when(principalCollectionMock.asList()).thenReturn(Arrays.asList(goodSecurityTokenMock));
when(securityManagerMock.getSubject(goodAuthenticationTokenMock)).thenReturn(subject);
when(securityManagerMock.getSubject(badAuthenticationTokenMock)).thenReturn(null);
when(sessionMock.getId()).thenReturn("sessionId");
when(requestMock.getSession(any(boolean.class))).thenReturn(sessionMock);
when(sessionFactory.getOrCreateSession(any())).thenReturn(sessionMock);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
when(sessionFactory.getOrCreateSession(any())).thenReturn(sessionMock);
when(sessionMock.getAttribute(SECURITY_TOKEN_KEY)).thenReturn(principalHolder);
when(contextPolicyManager.getSessionAccess()).thenReturn(true);
}
Aggregations