Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

spi-security: Support multiple realms #38

Open
danhaywood opened this issue Oct 13, 2017 · 0 comments
Open

spi-security: Support multiple realms #38

danhaywood opened this issue Oct 13, 2017 · 0 comments

Comments

@danhaywood
Copy link
Contributor

from isisaddons-legacy/isis-module-security#29

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

<pre>
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<? extends Realm> 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());
    }
}
</pre>


Here my shiro.ini:

<pre>
_[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 = *
_
</pre>
@danhaywood danhaywood changed the title module-security: Support multiple realms spi-security: Support multiple realms Oct 13, 2017
@danhaywood danhaywood added this to Backlog - Bugs in incode-platform (project) Oct 13, 2017
@danhaywood danhaywood moved this from Backlog - Bugs to Backlog - Feature Requests in incode-platform (project) Oct 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
incode-platform (project)
  
Backlog - Feature Requests
Development

No branches or pull requests

1 participant