Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple realms #29

Closed
niv0 opened this issue Apr 12, 2016 · 1 comment
Closed

Support multiple realms #29

niv0 opened this issue Apr 12, 2016 · 1 comment

Comments

@niv0
Copy link

niv0 commented Apr 12, 2016

I would like to use a shiro possibility to have multiple realms:

1.) to have in INI realm administrator uses
2.) thru this addon create additional users and authenticate them with their passwords

I've tried to adapt the AuthenticationStrategyForIsisModuleSecurityRealm, but it fails when tries to authentificate the user from addon, but failed.

Here the adapted Strategy, I've varied the subclassing of strategies, actually I would need "AtLeastOneSuccessfulStrategy" but failed

package security;

import java.util.Collection;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.pam.AllSuccessfulStrategy;
import org.apache.shiro.realm.Realm;

/**
 * Created by niv on 12.04.2016.
 */
public class AuthenticationStrategyForIsisModuleSecurityRealm2 extends AllSuccessfulStrategy {
    public AuthenticationStrategyForIsisModuleSecurityRealm2() {
    }

    @Override
    public AuthenticationInfo beforeAllAttempts(Collection realms, AuthenticationToken token) throws AuthenticationException {
        AuthenticationInfo auth = null;
        for (Realm realm : realms) {
            try {
                auth = realm.getAuthenticationInfo(token);
                if (auth != null)
                    return auth;

            } catch (IncorrectCredentialsException e) {
                System.out.println(e.getMessage());
                // catching when single realm throws authentification exception
            }
        }
        throw new AuthenticationException("no provided realms could't authenticate user, realm count:" + realms.size());
    }
}

Here my shiro.ini:

_[main]
isisModuleSecurityRealm=org.isisaddons.module.security.shiro.IsisModuleSecurityRealm
authenticationStrategy=security.AuthenticationStrategyForIsisModuleSecurityRealm2
securityManager.authenticator.authenticationStrategy =$authenticationStrategy
securityManager.realms =  $iniRealm,$isisModuleSecurityRealm

[users]
# user = password, role1, role2, role3, ...
sven = pass, admin_role, isis-module-security-admin
dick = pass, user_role, self-install_role
bob  = pass, user_role, self-install_role
joe  = pass, user_role, self-install_role
guest = guest, user_role


[roles]
user_role =   *:SimpleObjects:*:*,\
              *:SimpleObject:*:*
self-install_role = *:DomainAppFixtureService:*:*
admin_role = *
_
@danhaywood
Copy link
Contributor

moved to incodehq/incode-platform#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants