Search in sources :

Example 31 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SubjectImplTest method createTestCollection.

private PrincipalCollection createTestCollection() {
    SimplePrincipalCollection collection = new SimplePrincipalCollection();
    collection.add(TEST_SUBJECT_NAME, TEST_REALM_NAME);
    return collection;
}
Also used : SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Example 32 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SecurityManagerImplTest method testSecToken.

/**
     * Creates mock objects and uses those to pass through the system when a security token is used.
     *
     * @throws SecurityServiceException
     */
@Test
public void testSecToken() throws SecurityServiceException {
    // mock setup
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    SecurityToken secToken = new SecurityToken();
    principals.add(secToken, REALM_NAME);
    // realm
    Realm realm = mock(Realm.class);
    when(realm.getName()).thenReturn(REALM_NAME);
    SecurityManagerImpl manager = new SecurityManagerImpl();
    manager.setRealms(Arrays.asList(new Realm[] { realm }));
    Subject subject = manager.getSubject(secToken);
    assertNotNull(subject);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Realm(org.apache.shiro.realm.Realm) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 33 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class SecurityManagerImpl method createPrincipalFromToken.

/**
     * Creates a new principal object from an incoming security token.
     *
     * @param token SecurityToken that contains the principals.
     * @return new SimplePrincipalCollection
     */
private SimplePrincipalCollection createPrincipalFromToken(SecurityToken token) {
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    for (Realm curRealm : realms) {
        LOGGER.debug("Configuring settings for realm name: {} type: {}", curRealm.getName(), curRealm.getClass().toString());
        LOGGER.debug("Is authorizer: {}, is AuthorizingRealm: {}", curRealm instanceof Authorizer, curRealm instanceof AuthorizingRealm);
        SecurityAssertion securityAssertion = null;
        try {
            securityAssertion = new SecurityAssertionImpl(token, usernameAttributeList);
            Principal principal = securityAssertion.getPrincipal();
            if (principal != null) {
                principals.add(principal.getName(), curRealm.getName());
            }
        } catch (Exception e) {
            LOGGER.warn("Encountered error while trying to get the Principal for the SecurityToken. Security functions may not work properly.", e);
        }
        if (securityAssertion != null) {
            principals.add(securityAssertion, curRealm.getName());
        }
    }
    return principals;
}
Also used : Authorizer(org.apache.shiro.authz.Authorizer) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SecurityAssertion(ddf.security.assertion.SecurityAssertion) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Principal(java.security.Principal) SecurityServiceException(ddf.security.service.SecurityServiceException) SecurityAssertionImpl(ddf.security.assertion.impl.SecurityAssertionImpl)

Example 34 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project ddf by codice.

the class FilterPluginTest method setup.

@Before
public void setup() {
    AuthorizingRealm realm = mock(AuthorizingRealm.class);
    when(realm.getName()).thenReturn("mockRealm");
    when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
    Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
    realms.add(realm);
    DefaultSecurityManager manager = new DefaultSecurityManager();
    manager.setRealms(realms);
    SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {

        @Override
        public String getName() {
            return "testuser";
        }
    }, realm.getName());
    Subject systemSubject = new MockSubject(manager, principalCollection);
    plugin = new FilterPlugin() {

        @Override
        protected Subject getSystemSubject() {
            return systemSubject;
        }
    };
    QueryRequestImpl request = getSampleRequest();
    Map<String, Serializable> properties = new HashMap<>();
    Subject subject = new MockSubject(manager, principalCollection);
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    request.setProperties(properties);
    incomingResponse = new QueryResponseImpl(request);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    when(resourceRequest.getProperties()).thenReturn(properties);
    resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
    resourceResponse.setProperties(properties);
    DeleteRequest deleteRequest = mock(DeleteRequest.class);
    when(deleteRequest.getProperties()).thenReturn(properties);
    List<Metacard> deletedMetacards = new ArrayList<>();
    deletedMetacards.add(getExactRolesMetacard());
    deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
    List<Metacard> badDeletedMetacards = new ArrayList<>();
    badDeletedMetacards.add(getMoreRolesMetacard());
    badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
    createRequest = new CreateRequestImpl(getExactRolesMetacard());
    createRequest.setProperties(properties);
    badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
    badCreateRequest.setProperties(properties);
    updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
    updateRequest.setProperties(properties);
    ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
    ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
    ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
    ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
    ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
    incomingResponse.addResult(result1, false);
    incomingResponse.addResult(result2, false);
    incomingResponse.addResult(result3, false);
    incomingResponse.addResult(result4, false);
    incomingResponse.addResult(result5, true);
}
Also used : Serializable(java.io.Serializable) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) CollectionPermission(ddf.security.permission.CollectionPermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) Subject(ddf.security.Subject) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Principal(java.security.Principal) Before(org.junit.Before)

Example 35 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project perry by ca-cwds.

the class AbstractRealm method getAuthenticationInfo.

private AuthenticationInfo getAuthenticationInfo(PerryAccount perryAccount, String token) {
    List<Object> principals = new ArrayList<>();
    principals.add(perryAccount.getUser());
    principals.add(perryAccount);
    principals.add(token);
    PrincipalCollection principalCollection = new SimplePrincipalCollection(principals, getName());
    return new SimpleAuthenticationInfo(principalCollection, "N/A");
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection)

Aggregations

SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)55 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)26 Test (org.junit.Test)25 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)11 ArrayList (java.util.ArrayList)7 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)7 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)7 Realm (org.apache.shiro.realm.Realm)7 Principal (java.security.Principal)6 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)6 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 Subject (org.apache.shiro.subject.Subject)6 Subject (ddf.security.Subject)5 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)5 SimpleAccount (org.apache.shiro.authc.SimpleAccount)5 AuthorizingRealm (org.apache.shiro.realm.AuthorizingRealm)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 SecurityAssertion (ddf.security.assertion.SecurityAssertion)4 HashSet (java.util.HashSet)4 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)4