Example usage for org.apache.shiro.subject SubjectContext setSecurityManager

List of usage examples for org.apache.shiro.subject SubjectContext setSecurityManager

Introduction

In this page you can find the example usage for org.apache.shiro.subject SubjectContext setSecurityManager.

Prototype

void setSecurityManager(SecurityManager securityManager);

Source Link

Document

Sets the SecurityManager instance that should be used to back the constructed Subject instance (typically used to support org.apache.shiro.subject.support.DelegatingSubject DelegatingSubject implementations).

Usage

From source file:br.com.criativasoft.opendevice.wsrest.RestWebSecurityManager.java

License:Open Source License

@Override
protected Subject createSubject(AuthenticationToken token, AuthenticationInfo info, Subject existing) {
    SubjectContext context = createSubjectContext();
    context.setAuthenticated(true);/*from   ww w  . j av  a 2  s  .  c om*/
    context.setAuthenticationToken(token);
    context.setAuthenticationInfo(info);
    if (existing != null) {
        // FIX Avoid session creation if previous Subject is disabled.
        // org.apache.shiro.subject.SubjectContext.isSessionCreationEnabled()
        if (existing instanceof WebDelegatingSubject) {
            context.setSessionCreationEnabled(WebUtils._isSessionCreationEnabled(this));
            context.setSecurityManager(((WebDelegatingSubject) existing).getSecurityManager());
        }
        context.setSubject(existing);
    }
    return createSubject(context);
}

From source file:com.caricah.iotracah.bootstrap.security.IOTSecurityManager.java

License:Apache License

/**
 * Determines if there is a {@code SecurityManager} instance in the context, and if not, adds 'this' to the
 * context.  This ensures the SubjectFactory instance will have access to a SecurityManager during Subject
 * construction if necessary./*from w  ww . ja v  a 2 s  . co m*/
 *
 * @param context the subject context data that may contain a SecurityManager instance.
 * @return The SubjectContext to use to pass to a {@link SubjectFactory} for subject creation.
 * @since 1.0
 */
@SuppressWarnings({ "unchecked" })
protected SubjectContext ensureSecurityManager(SubjectContext context) {
    if (context.resolveSecurityManager() != null) {
        log.trace("Context already contains a SecurityManager instance.  Returning.");
        return context;
    }
    log.trace("No SecurityManager found in context.  Adding self reference.");
    context.setSecurityManager(this);
    return context;
}