Search in sources :

Example 11 with Realm

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

the class DefaultSecurityApi method invalidateJDBCAuthorizationCache.

private void invalidateJDBCAuthorizationCache(final String username) {
    final Collection<Realm> realms = ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getRealms();
    final KillBillJdbcRealm killBillJdbcRealm = (KillBillJdbcRealm) Iterables.tryFind(realms, new Predicate<Realm>() {

        @Override
        public boolean apply(@Nullable final Realm input) {
            return (input instanceof KillBillJdbcRealm);
        }
    }).orNull();
    if (killBillJdbcRealm != null) {
        final SimplePrincipalCollection principals = new SimplePrincipalCollection();
        principals.add(username, killBillJdbcRealm.getName());
        killBillJdbcRealm.clearCachedAuthorizationInfo(principals);
    }
}
Also used : KillBillJdbcRealm(org.killbill.billing.util.security.shiro.realm.KillBillJdbcRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Realm(org.apache.shiro.realm.Realm) KillBillJdbcRealm(org.killbill.billing.util.security.shiro.realm.KillBillJdbcRealm)

Example 12 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)

Example 13 with Realm

use of org.apache.shiro.realm.Realm in project dropwizard-shiro by silb.

the class ShiroBundle method createFilter.

/**
     * Create the Shiro filter. Overriding this method allows for complete customization of how Shiro is initialized.
     */
protected Filter createFilter(final T configuration) {
    ShiroConfiguration shiroConfig = narrow(configuration);
    final IniWebEnvironment shiroEnv = new IniWebEnvironment();
    shiroEnv.setConfigLocations(shiroConfig.iniConfigs());
    shiroEnv.init();
    AbstractShiroFilter shiroFilter = new AbstractShiroFilter() {

        @Override
        public void init() throws Exception {
            Collection<Realm> realms = createRealms(configuration);
            WebSecurityManager securityManager = realms.isEmpty() ? shiroEnv.getWebSecurityManager() : new DefaultWebSecurityManager(realms);
            setSecurityManager(securityManager);
            setFilterChainResolver(shiroEnv.getFilterChainResolver());
        }
    };
    return shiroFilter;
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) AbstractShiroFilter(org.apache.shiro.web.servlet.AbstractShiroFilter) IniWebEnvironment(org.apache.shiro.web.env.IniWebEnvironment) Realm(org.apache.shiro.realm.Realm)

Example 14 with Realm

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

the class SecurityManagerImplTest method testAuthTokenNoRealm.

/**
     * Test to check for failure when no realms are added.
     *
     * @throws SecurityServiceException
     */
@Test
public void testAuthTokenNoRealm() throws SecurityServiceException {
    thrown.expect(org.apache.shiro.authc.AuthenticationException.class);
    thrown.expectMessage("Authentication failed for token submission");
    AuthenticationToken token = mock(AuthenticationToken.class);
    when(token.getCredentials()).thenReturn("testUser");
    AuthenticationInfo info = mock(AuthenticationInfo.class);
    Realm realm = mock(Realm.class);
    when(realm.getAuthenticationInfo(token)).thenReturn(info);
    SecurityManagerImpl manager = new SecurityManagerImpl();
    manager.getSubject(token);
}
Also used : AuthenticationToken(org.apache.shiro.authc.AuthenticationToken) Realm(org.apache.shiro.realm.Realm) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo) Test(org.junit.Test)

Example 15 with Realm

use of org.apache.shiro.realm.Realm 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)

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