Package org.apache.shiro.subject

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


  public Subject login(AuthenticationToken token)
      throws AuthenticationException
  {
    try {
      Subject subject = this.getSubject();
      subject.login(token);
      return subject;
    }
    catch (org.apache.shiro.authc.AuthenticationException e) {
      throw new AuthenticationException(e.getMessage(), e);
    }
View Full Code Here


        // Example using most common scenario of username/password pair:
        UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
        Subject currentUser = SecurityUtils.getSubject();

        try {
            currentUser.login(token);
            return "success";
        } catch (AuthenticationException e) {
            // Could catch a subclass of AuthenticationException if you like
            FacesContext.getCurrentInstance().addMessage(
                    null,
View Full Code Here

    public void testLoginSuccess() {
        createUser(username, password);

        UsernamePasswordToken upToken = new UsernamePasswordToken(username, password);
        Subject subject = SecurityUtils.getSubject();
        subject.login(upToken);
        Assert.assertEquals(username, subject.getPrincipal());
    }

    @Test(expected = UnknownAccountException.class)
    public void testLoginFailWithUserNotExists() {
View Full Code Here

    public void testLoginFailWithUserNotExists() {
        createUser(username, password);

        UsernamePasswordToken upToken = new UsernamePasswordToken(username + "1", password);
        Subject subject = SecurityUtils.getSubject();
        subject.login(upToken);
    }

    @Test(expected = AuthenticationException.class)
    public void testLoginFailWithUserPasswordNotMatch() {
        createUser(username, password);
View Full Code Here

    public void testLoginFailWithUserPasswordNotMatch() {
        createUser(username, password);

        UsernamePasswordToken upToken = new UsernamePasswordToken(username, password + "1");
        Subject subject = SecurityUtils.getSubject();
        subject.login(upToken);
    }


    @Test(expected = LockedAccountException.class)
    public void testLoginFailWithSysBlocked() {
View Full Code Here

        User user = createUser(username, password);
        userService.changeStatus(user, user, UserStatus.blocked, "sql");

        UsernamePasswordToken upToken = new UsernamePasswordToken(username, password);
        Subject subject = SecurityUtils.getSubject();
        subject.login(upToken);

    }

    @Test(expected = ExcessiveAttemptsException.class)
    public void testLoginFailWithRetryLimitExceed() {
View Full Code Here

        createUser(username, password);
        for (int i = 0; i < maxtRetryCount; i++) {
            try {
                UsernamePasswordToken upToken = new UsernamePasswordToken(username, password + "1");
                Subject subject = SecurityUtils.getSubject();
                subject.login(upToken);
            } catch (AuthenticationException e) {
            }
        }

        UsernamePasswordToken upToken = new UsernamePasswordToken(username, password);
View Full Code Here

            }
        }

        UsernamePasswordToken upToken = new UsernamePasswordToken(username, password);
        Subject subject = SecurityUtils.getSubject();
        subject.login(upToken);
    }


    private User createUser(String username, String password) {
        User user = new User();
View Full Code Here

                    "must be created in order to execute a login attempt.";
            throw new IllegalStateException(msg);
        }
        try {
            Subject subject = getSubject(request, response);
            subject.login(token);
            return onLoginSuccess(token, subject, request, response);
        } catch (AuthenticationException e) {
            return onLoginFailure(token, e, request, response);
        }
    }
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

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.