use of org.apache.shiro.realm.AuthorizingRealm 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);
}
use of org.apache.shiro.realm.AuthorizingRealm in project shiro by apache.
the class AllSuccessfulStrategyTest method beforeAttemptRealmDoesntSupportToken.
@Test(expected = UnsupportedTokenException.class)
public void beforeAttemptRealmDoesntSupportToken() {
Realm notSupportingRealm = new AuthorizingRealm() {
public boolean supports(AuthenticationToken token) {
return false;
}
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
return null;
}
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principal) {
return null;
}
};
strategy.beforeAttempt(notSupportingRealm, null, null);
}
use of org.apache.shiro.realm.AuthorizingRealm in project ddf by codice.
the class OperationPluginTest method setup.
@Before
public void setup() {
plugin = new OperationPlugin();
plugin.setPermissions(new PermissionsImpl());
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);
}
use of org.apache.shiro.realm.AuthorizingRealm 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;
}
use of org.apache.shiro.realm.AuthorizingRealm in project nutzboot by nutzam.
the class ShiroEnvStarter method getWebSecurityManager.
@IocBean(name = "shiroWebSecurityManager")
public WebSecurityManager getWebSecurityManager() {
DefaultWebSecurityManager webSecurityManager = new DefaultWebSecurityManager() {
protected SubjectContext resolveSession(SubjectContext context) {
if (context.resolveSession() != null) {
return context;
}
try {
Session session = resolveContextSession(context);
if (session != null) {
context.setSession(session);
}
} catch (InvalidSessionException e) {
}
return context;
}
};
// Shiro Session相关
if (conf.getBoolean(PROP_SESSION_ENABLE, true)) {
webSecurityManager.setSessionManager(ioc.get(WebSessionManager.class, "shiroWebSessionManager"));
}
List<Realm> realms = new ArrayList<>();
for (String realmName : ioc.getNamesByType(Realm.class)) {
AuthorizingRealm realm = ioc.get(AuthorizingRealm.class, realmName);
if (conf.getBoolean(PROP_REALM_CACHE_ENABLE, false)) {
realm.setCacheManager(ioc.get(CacheManager.class, "shiroCacheManager"));
}
realms.add(realm);
}
if (ioc.has("authenticationStrategy")) {
ModularRealmAuthenticator modularRealmAuthenticator = new ModularRealmAuthenticator();
modularRealmAuthenticator.setAuthenticationStrategy(ioc.get(AuthenticationStrategy.class, "authenticationStrategy"));
if (realms.size() > 0)
modularRealmAuthenticator.setRealms(realms);
webSecurityManager.setAuthenticator(modularRealmAuthenticator);
}
if (realms.size() > 0)
webSecurityManager.setRealms(realms);
webSecurityManager.setRememberMeManager(ioc.get(RememberMeManager.class, "shiroRememberMeManager"));
return webSecurityManager;
}
Aggregations