Search in sources :

Example 6 with Realm

use of org.apache.shiro.realm.Realm in project geode by apache.

the class IntegratedSecurityService method setSecurityManager.

public void setSecurityManager(SecurityManager securityManager) {
    if (securityManager == null) {
        return;
    }
    this.securityManager = securityManager;
    Realm realm = new CustomAuthRealm(securityManager);
    DefaultSecurityManager shiroManager = new DefaultSecurityManager(realm);
    SecurityUtils.setSecurityManager(shiroManager);
    increaseShiroGlobalSessionTimeout(shiroManager);
    isIntegratedSecurity = true;
    isClientAuthenticator = false;
    isPeerAuthenticator = false;
}
Also used : CustomAuthRealm(org.apache.geode.internal.security.shiro.CustomAuthRealm) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Realm(org.apache.shiro.realm.Realm) CustomAuthRealm(org.apache.geode.internal.security.shiro.CustomAuthRealm)

Example 7 with Realm

use of org.apache.shiro.realm.Realm in project ddf by codice.

the class SecurityManagerImplTest method testAuthToken.

/**
     * Creates mock objects and uses those to pass through the system when an authentication token
     * is used.
     *
     * @throws SecurityServiceException
     */
@Test
public void testAuthToken() throws SecurityServiceException {
    // mock setup
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    SecurityToken secToken = new SecurityToken();
    principals.add(secToken, REALM_NAME);
    AuthenticationToken authToken = mock(AuthenticationToken.class);
    when(authToken.getCredentials()).thenReturn("testUser");
    AuthenticationInfo info = mock(AuthenticationInfo.class);
    when(info.getPrincipals()).thenReturn(principals);
    // realm
    Realm realm = mock(Realm.class);
    when(realm.getAuthenticationInfo(authToken)).thenReturn(info);
    when(realm.supports(authToken)).thenReturn(Boolean.TRUE);
    when(realm.getName()).thenReturn(REALM_NAME);
    SecurityManagerImpl manager = new SecurityManagerImpl();
    manager.setRealms(Arrays.asList(new Realm[] { realm }));
    Subject subject = manager.getSubject(authToken);
    assertNotNull(subject);
}
Also used : SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Realm(org.apache.shiro.realm.Realm) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 8 with Realm

use of org.apache.shiro.realm.Realm in project ddf by codice.

the class OperationPluginTest method setup.

@Before
public void setup() {
    plugin = new OperationPlugin();
    AuthorizingRealm realm = mock(AuthorizingRealm.class);
    when(realm.getName()).thenReturn("mockRealm");
    when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
    Collection<Realm> realms = new ArrayList<Realm>();
    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 = new MockSubject(manager, principalCollection);
}
Also used : ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) CollectionPermission(ddf.security.permission.CollectionPermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Principal(java.security.Principal) Before(org.junit.Before)

Example 9 with Realm

use of org.apache.shiro.realm.Realm in project ddf by codice.

the class TestResourceUsagePlugin method setSubject.

private void setSubject(String expectedUsername) {
    AuthorizingRealm realm = mock(AuthorizingRealm.class);
    when(realm.getName()).thenReturn("mockRealm");
    when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).thenReturn(true);
    Collection<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 expectedUsername;
        }

        @Override
        public String toString() {
            return expectedUsername;
        }
    }, realm.getName());
    subject = new MockSubject(manager, principalCollection);
}
Also used : Permission(org.apache.shiro.authz.Permission) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Matchers.anyString(org.mockito.Matchers.anyString) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Principal(java.security.Principal)

Example 10 with Realm

use of org.apache.shiro.realm.Realm in project zeppelin by apache.

the class SecurityUtils method getRealmsList.

public static Collection getRealmsList() {
    if (!isEnabled) {
        return Collections.emptyList();
    }
    DefaultWebSecurityManager defaultWebSecurityManager;
    String key = ThreadContext.SECURITY_MANAGER_KEY;
    defaultWebSecurityManager = (DefaultWebSecurityManager) ThreadContext.get(key);
    Collection<Realm> realms = defaultWebSecurityManager.getRealms();
    return realms;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) IniRealm(org.apache.shiro.realm.text.IniRealm) LdapRealm(org.apache.zeppelin.realm.LdapRealm) Realm(org.apache.shiro.realm.Realm)

Aggregations

Realm (org.apache.shiro.realm.Realm)16 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)6 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)5 IniRealm (org.apache.shiro.realm.text.IniRealm)4 Principal (java.security.Principal)3 ArrayList (java.util.ArrayList)3 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)3 AuthorizingRealm (org.apache.shiro.realm.AuthorizingRealm)3 LdapRealm (org.apache.zeppelin.realm.LdapRealm)3 Subject (ddf.security.Subject)2 HashSet (java.util.HashSet)2 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)2 AuthenticationToken (org.apache.shiro.authc.AuthenticationToken)2 Permission (org.apache.shiro.authz.Permission)2 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)2 DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)2 Before (org.junit.Before)2 Test (org.junit.Test)2 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)2 BasicPasswordPolicy (org.neo4j.server.security.auth.BasicPasswordPolicy)2