use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class RestSecurityTest method testNotSetSubjectOnClient.
@Test
public void testNotSetSubjectOnClient() throws Exception {
Element samlToken = readDocument("/saml.xml").getDocumentElement();
Subject subject = mock(Subject.class);
SecurityAssertion assertion = mock(SecurityAssertion.class);
SecurityToken token = new SecurityToken(UUID.randomUUID().toString(), samlToken, new Date(), new Date());
when(assertion.getSecurityToken()).thenReturn(token);
when(subject.getPrincipals()).thenReturn(new SimplePrincipalCollection(assertion, "sts"));
WebClient client = WebClient.create("http://example.org");
RestSecurity.setSubjectOnClient(subject, client);
assertNull(client.getHeaders().get(RestSecurity.AUTH_HEADER));
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class AbstractStsRealm method doGetAuthenticationInfo.
/**
* Perform authentication based on the supplied token.
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
String method = "doGetAuthenticationInfo( AuthenticationToken token )";
Object credential;
if (token instanceof SAMLAuthenticationToken) {
credential = token.getCredentials();
} else if (token instanceof BaseAuthenticationToken) {
credential = ((BaseAuthenticationToken) token).getCredentialsAsXMLString();
} else {
credential = token.getCredentials().toString();
}
if (credential == null) {
String msg = "Unable to authenticate credential. A NULL credential was provided in the supplied authentication token. This may be due to an error with the SSO server that created the token.";
LOGGER.info(msg);
throw new AuthenticationException(msg);
} else {
//removed the credentials from the log message for now, I don't think we should be dumping user/pass into log
LOGGER.debug("Received credentials.");
}
SecurityToken securityToken;
if (token instanceof SAMLAuthenticationToken && credential instanceof SecurityToken) {
securityToken = renewSecurityToken((SecurityToken) credential);
} else {
securityToken = requestSecurityToken(credential);
}
LOGGER.debug("Creating token authentication information with SAML.");
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
SimplePrincipalCollection principals = new SimplePrincipalCollection();
SecurityAssertion assertion = new SecurityAssertionImpl(securityToken);
principals.add(assertion.getPrincipal(), NAME);
principals.add(assertion, NAME);
simpleAuthenticationInfo.setPrincipals(principals);
simpleAuthenticationInfo.setCredentials(credential);
return simpleAuthenticationInfo;
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SubjectUtilsTest method testGetName.
@Test
public void testGetName() {
org.apache.shiro.subject.Subject subject;
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection(TEST_NAME, "testrealm");
subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
assertEquals(TEST_NAME, SubjectUtils.getName(subject));
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class SubjectUtilsTest method testGetDefaultName.
@Test
public void testGetDefaultName() {
org.apache.shiro.subject.Subject subject;
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection();
subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
assertEquals(DEFAULT_NAME, SubjectUtils.getName(subject, DEFAULT_NAME));
assertEquals(DEFAULT_NAME, SubjectUtils.getName(null, DEFAULT_NAME));
}
use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.
the class AbstractDownloadsStatusEventPublisherTest method addSecurity.
private void addSecurity() {
org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager();
PrincipalCollection principals = new SimplePrincipalCollection(USER_ID, "testrealm");
Subject subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()).authenticated(true).buildSubject();
ThreadContext.bind(secManager);
ThreadContext.bind(subject);
}
Aggregations