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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations