Example usage for org.apache.shiro SecurityUtils getSecurityManager

List of usage examples for org.apache.shiro SecurityUtils getSecurityManager

Introduction

In this page you can find the example usage for org.apache.shiro SecurityUtils getSecurityManager.

Prototype

public static SecurityManager getSecurityManager() throws UnavailableSecurityManagerException 

Source Link

Document

Returns the SecurityManager accessible to the calling code.

Usage

From source file:org.obiba.mica.security.SubjectUtils.java

License:Open Source License

public static <V> V sudo(Callable<V> callable) {
    Subject sudo = new Subject.Builder()
            .principals(SecurityUtils.getSecurityManager()
                    .authenticate(new SudoAuthToken(SecurityUtils.getSubject())).getPrincipals())
            .authenticated(true).buildSubject();

    return sudo.execute(callable);
}

From source file:org.obiba.onyx.webapp.OnyxAuthenticatedSession.java

License:Open Source License

public final boolean authenticate(final String password) {
    try {/*from w  w w.  ja  va 2  s. co m*/
        Subject currentUser = SecurityUtils.getSubject();
        SecurityUtils.getSecurityManager().authenticate(
                new UsernamePasswordToken((String) currentUser.getPrincipal(), password.toCharArray()));
        return true;
    } catch (AuthenticationException e) {
        return false;
    }
}

From source file:org.obiba.opal.core.runtime.BackgroundJobService.java

License:Open Source License

private Subject getSubject() {
    // Login as background job user
    try {/*from   w ww.  j  ava2  s  . c  om*/
        PrincipalCollection principals = SecurityUtils.getSecurityManager()
                .authenticate(new BackgroundJobServiceAuthToken()).getPrincipals();
        return new Subject.Builder().principals(principals).authenticated(true).buildSubject();
    } catch (AuthenticationException e) {
        log.warn("Failed to obtain system user credentials: {}", e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:org.obiba.opal.core.runtime.security.AbstractHttpAuthenticatingRealm.java

License:Open Source License

@Nullable
protected SessionManager getSessionManager() {
    SecurityManager sm = SecurityUtils.getSecurityManager();
    if (sm instanceof SessionsSecurityManager)
        return sm;
    return null;/*from www  .ja  v a 2s.c o m*/
}

From source file:org.obiba.opal.core.service.BackgroundJobService.java

License:Open Source License

private Subject getSubject() {
    // Login as background task user
    try {/* www. j  ava2s.  co m*/
        PrincipalCollection principals = SecurityUtils.getSecurityManager()
                .authenticate(BackgroundJobServiceAuthToken.INSTANCE).getPrincipals();
        return new Subject.Builder().principals(principals).authenticated(true).buildSubject();
    } catch (AuthenticationException e) {
        log.warn("Failed to obtain system user credentials: {}", e.getMessage());
        throw new RuntimeException(e);
    }
}

From source file:org.obiba.opal.shell.service.impl.quartz.QuartzCommandJob.java

License:Open Source License

private Subject getSubject(JobExecutionContext context) {
    PrincipalCollection principals = (PrincipalCollection) context.getJobDetail().getJobDataMap()
            .get("subject");
    if (principals == null) {
        // Login as background job user
        principals = SecurityUtils.getSecurityManager().authenticate(new BackgroundJobServiceAuthToken())
                .getPrincipals();/*from   w  w  w  .j  ava  2s .c  om*/
    }
    return new Subject.Builder().principals(principals).authenticated(true).buildSubject();
}

From source file:org.obiba.shiro.realm.AbstractHttpAuthenticatingRealm.java

License:Open Source License

@Nullable
protected SessionManager getSessionManager() {
    SecurityManager sm = SecurityUtils.getSecurityManager();
    return sm instanceof SessionsSecurityManager ? sm : null;
}

From source file:org.obiba.shiro.web.filter.AbstractAuthenticationExecutor.java

License:Open Source License

@Override
public Subject login(AuthenticationToken token, String sessionId) throws AuthenticationException {
    Subject subject = sessionId == null ? SecurityUtils.getSubject()
            : new Subject.Builder(SecurityUtils.getSecurityManager()).sessionId(sessionId).buildSubject();

    if (!subject.isAuthenticated()) {
        subject.login(token);// w  w w  .j a v  a2 s  .co  m
        ThreadContext.bind(subject);
        ensureProfile(subject);
    }
    return subject.isAuthenticated() ? subject : null;
}

From source file:org.openengsb.itests.util.AbstractExamTestHelper.java

License:Apache License

protected void waitForUserDataInitializer() throws InterruptedException {
    SecurityManager sm = null;//from   w  ww .j a v a 2s  . com
    int count = 0;
    while (sm == null) {
        try {
            sm = SecurityUtils.getSecurityManager();
        } catch (UnavailableSecurityManagerException e) {
            LOGGER.warn("waiting for security-manager to be set");
            waitasec();
        }
        if (count++ > 100) {
            throw new IllegalStateException("security-manager was not set in time");
        }
    }
    UserDataManager userDataManager = getOsgiService(UserDataManager.class, "(internal=true)", 20000);
    count = 0;
    while (userDataManager.getUserList().isEmpty()) {
        LOGGER.warn("waiting for users to be initialized");
        waitasec();
        if (count++ > 100) {
            throw new IllegalStateException("user-data-initializer did not finish in time");
        }
    }
    getOsgiService(AuthenticationDomain.class, "(connector=usernamepassword)", 15000);
}

From source file:org.openiot.security.client.AccessControlUtil.java

License:Open Source License

public AuthorizationManager getAuthorizationManager() {
    if (authorizationManager == null) {
        ACRealm acRealm = (ACRealm) getCasOAuthClientRealm();
        authorizationManager = new AuthorizationManager();
        authorizationManager.setClient(getClient());
        authorizationManager.setPermissionsURL(acRealm.getPermissionsURL());
        authorizationManager.setCacheManager(
                ((CachingSecurityManager) SecurityUtils.getSecurityManager()).getCacheManager());
        acRealm.addClearCacheListener(authorizationManager);
    }/*from   w w  w . ja  v  a  2 s.  c o  m*/
    return authorizationManager;
}