Search in sources :

Example 6 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory in project qi4j-sdk by Qi4j.

the class StandaloneShiroTest method documentationSupport_before.

public void documentationSupport_before() {
    // START SNIPPET: before
    IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:standalone-shiro.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
// END SNIPPET: before
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager)

Example 7 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory in project geode by apache.

the class IntegratedSecurityService method initSecurity.

/**
   * initialize Shiro's Security Manager and Security Utilities
   */
public void initSecurity(Properties securityProps) {
    if (securityProps == null) {
        return;
    }
    String shiroConfig = securityProps.getProperty(SECURITY_SHIRO_INIT);
    String securityManagerConfig = securityProps.getProperty(SECURITY_MANAGER);
    String clientAuthenticatorConfig = securityProps.getProperty(SECURITY_CLIENT_AUTHENTICATOR);
    String peerAuthenticatorConfig = securityProps.getProperty(SECURITY_PEER_AUTHENTICATOR);
    if (StringUtils.isNotBlank(shiroConfig)) {
        IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:" + shiroConfig);
        // we will need to make sure that shiro uses a case sensitive permission resolver
        Section main = factory.getIni().addSection("main");
        main.put("geodePermissionResolver", "org.apache.geode.internal.security.shiro.GeodePermissionResolver");
        if (!main.containsKey("iniRealm.permissionResolver")) {
            main.put("iniRealm.permissionResolver", "$geodePermissionResolver");
        }
        org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        isIntegratedSecurity = true;
        isClientAuthenticator = false;
        isPeerAuthenticator = false;
    } else // only set up shiro realm if user has implemented SecurityManager
    if (StringUtils.isNotBlank(securityManagerConfig)) {
        SecurityManager securityManager = SecurityService.getObjectOfTypeFromClassName(securityManagerConfig, SecurityManager.class);
        securityManager.init(securityProps);
        this.setSecurityManager(securityManager);
    } else {
        isIntegratedSecurity = null;
        isClientAuthenticator = StringUtils.isNotBlank(clientAuthenticatorConfig);
        isPeerAuthenticator = StringUtils.isNotBlank(peerAuthenticatorConfig);
    }
    // this initializes the post processor
    String customPostProcessor = securityProps.getProperty(SECURITY_POST_PROCESSOR);
    if (StringUtils.isNotBlank(customPostProcessor)) {
        postProcessor = SecurityService.getObjectOfTypeFromClassName(customPostProcessor, PostProcessor.class);
        postProcessor.init(securityProps);
    } else {
        postProcessor = null;
    }
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) SecurityManager(org.apache.geode.security.SecurityManager) Section(org.apache.shiro.config.Ini.Section) PostProcessor(org.apache.geode.security.PostProcessor)

Example 8 with IniSecurityManagerFactory

use of org.apache.shiro.config.IniSecurityManagerFactory in project bamboobsc by billchen198318.

the class SubjectBuilderForBackground method login.

public static void login() throws Exception {
    Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    org.apache.shiro.mgt.SecurityManager securityManager = (org.apache.shiro.mgt.SecurityManager) factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
    Subject currentUser = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(Constants.SYSTEM_BACKGROUND_USER, Constants.SYSTEM_BACKGROUND_PASSWORD);
    currentUser.login(token);
//System.out.println(currentUser.hasRole("admin"));
//System.out.println(currentUser.hasRole("*"));
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) Subject(org.apache.shiro.subject.Subject) UsernamePasswordToken(org.apache.shiro.authc.UsernamePasswordToken)

Aggregations

IniSecurityManagerFactory (org.apache.shiro.config.IniSecurityManagerFactory)8 SecurityManager (org.apache.shiro.mgt.SecurityManager)6 Ini (org.apache.shiro.config.Ini)2 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)2 GeneralSecurityException (java.security.GeneralSecurityException)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)1 FailedLoginException (javax.security.auth.login.FailedLoginException)1 PostProcessor (org.apache.geode.security.PostProcessor)1 SecurityManager (org.apache.geode.security.SecurityManager)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 DisabledAccountException (org.apache.shiro.authc.DisabledAccountException)1 ExcessiveAttemptsException (org.apache.shiro.authc.ExcessiveAttemptsException)1 ExpiredCredentialsException (org.apache.shiro.authc.ExpiredCredentialsException)1 IncorrectCredentialsException (org.apache.shiro.authc.IncorrectCredentialsException)1 LockedAccountException (org.apache.shiro.authc.LockedAccountException)1 UnknownAccountException (org.apache.shiro.authc.UnknownAccountException)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 ConfigurationException (org.apache.shiro.config.ConfigurationException)1