Example usage for org.apache.shiro.mgt DefaultSecurityManager createSubject

List of usage examples for org.apache.shiro.mgt DefaultSecurityManager createSubject

Introduction

In this page you can find the example usage for org.apache.shiro.mgt DefaultSecurityManager createSubject.

Prototype

public Subject createSubject(SubjectContext subjectContext) 

Source Link

Document

This implementation functions as follows:

  1. Ensures the SubjectContext is as populated as it can be, using heuristics to acquire data that may not have already been available to it (such as a referenced session or remembered principals).
  2. Calls #doCreateSubject(org.apache.shiro.subject.SubjectContext) to actually perform the Subject instance creation.
  3. calls #save(org.apache.shiro.subject.Subject) save(subject) to ensure the constructed Subject 's state is accessible for future requests/invocations if necessary.
  4. returns the constructed Subject instance.

Usage

From source file:org.openengsb.core.security.internal.RootSubjectHolder.java

License:Apache License

public static void init() {
    DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
    defaultSecurityManager.setAuthenticator(new Authenticator() {
        @Override/* w w  w  .  j a va 2  s  .  c  o m*/
        public AuthenticationInfo authenticate(AuthenticationToken authenticationToken)
                throws AuthenticationException {
            return new SimpleAuthenticationInfo(new Object(), null, "openengsb");
        }
    });
    Subject subject = defaultSecurityManager.createSubject(new DefaultSubjectContext());
    synchronized (rootSubject) {
        rootSubject.set(defaultSecurityManager.login(subject, null));
        rootSubject.notifyAll();
    }
}