Package org.apache.shiro.subject

Examples of org.apache.shiro.subject.Subject.login()


        IniSecurityManagerFactory factory = new IniSecurityManagerFactory(ini);
        SecurityManager sm = factory.getInstance();

        //try to log-in:
        Subject subject = new Subject.Builder(sm).buildSubject();
        subject.login(new UsernamePasswordToken("admin", "admin"));
        Session session = subject.getSession();
        session.setAttribute("hello", "world");
        //session should have been started, and a cache is in use.  Assert that the SessionDAO is still using
        //the cache instances provided by our custom CacheManager and not the Default MemoryConstrainedCacheManager
View Full Code Here


        Subject subject = newSubject(mockRequest, mockResponse);

        assertFalse(subject.isAuthenticated());

        subject.login(new UsernamePasswordToken("lonestarr", "vespa"));

        assertTrue(subject.isAuthenticated());
        assertNotNull(subject.getPrincipal());
        assertTrue(subject.getPrincipal().equals("lonestarr"));
    }
View Full Code Here

      //
      return new Response.Error(e);
    }

    try {
      subject.login(new UsernamePasswordToken(username, password.toCharArray(), remember));

      //
      Response resp = stage.invoke();
      if (remember && rememberMeSupported) {
        RememberMeUtil.forgetIdentity();
View Full Code Here

      if (!subject.isAuthenticated())
      {
        final UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        token.setRememberMe(rememberMe);
        subject.login(token);
      }

      logger.info(String.format("Login succeeded for %s", subject.getPrincipal()));
      return true;
    }
View Full Code Here

           
            // for now, just log them out.
            currentUser.logout();
        }
        try {
            currentUser.login(token);
        } catch ( UnknownAccountException uae ) {
            LOG.debug("Unable to authenticate", uae);
            return null;
        } catch ( IncorrectCredentialsException ice ) {
            LOG.debug("Unable to authenticate", ice);
View Full Code Here

       
        UsernamePasswordToken token;
        token = new UsernamePasswordToken(email, password, remember);
        try
        {
            currentUser.login(token);
            return true;
        }
        catch (AuthenticationException ae)
        {
            onAuthenticationException(ae);
View Full Code Here

    @Override
    public void login(String username, Credentials credentials) {
        Subject subject = SecurityUtils.getSubject();
        OpenEngSBAuthenticationToken token = new OpenEngSBAuthenticationToken(username, credentials);
        subject.login(token);
    }

    @Override
    public void logout() {
        Subject subject = ThreadContext.getSubject();
View Full Code Here

        result.get();
    }

    private void authenticate(String user, String password) {
        Subject subject = SecurityUtils.getSubject();
        subject.login(new OpenEngSBAuthenticationToken(user, new Password(password)));
    }
}
View Full Code Here

     */
    public static <ReturnType> ReturnType executeWithSystemPermissions(Callable<ReturnType> task)
        throws ExecutionException {
        ContextAwareCallable<ReturnType> contextAwareCallable = new ContextAwareCallable<ReturnType>(task);
        Subject newsubject = new Subject.Builder().buildSubject();
        newsubject.login(new RootAuthenticationToken());
        try {
            return newsubject.execute(contextAwareCallable);
        } finally {
            newsubject.logout();
        }
View Full Code Here

     * wraps an existing ExecutorService to handle context- and security-related threadlocal variables
     */
    public static void executeWithSystemPermissions(Runnable task) {
        ContextAwareRunnable contextAwaretask = new ContextAwareRunnable(task);
        Subject newsubject = new Subject.Builder().buildSubject();
        newsubject.login(new RootAuthenticationToken());
        try {
            newsubject.execute(contextAwaretask);
        } finally {
            newsubject.logout();
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.