Examples of checkRole()


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

        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(u1.getUsername(), password);
        subject.login(token);

        Assert.assertTrue(subject.isAuthenticated());
        subject.checkRole("admin");
        subject.checkPermission("user:create");

        userService.changePassword(u1.getId(), password + "1");
        userRealm.clearCache(subject.getPrincipals());
View Full Code Here

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

public class RoleServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Subject subject = SecurityUtils.getSubject();
        subject.checkRole("admin");
        req.getRequestDispatcher("/WEB-INF/jsp/hasRole.jsp").forward(req, resp);
    }
}
View Full Code Here

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

  @Override
  public void assertAuthorized() throws AuthorizationException {
    Subject subject = getSubject();
    //数据库权限
    if (jdbcRole != null) {
      subject.checkRole(jdbcRole);
      return;
    }
  }
}
View Full Code Here

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

    if (!(annotation instanceof RequiresRoles)) return;
    RequiresRoles rrAnnotation = (RequiresRoles) annotation;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
      subject.checkRole(roles[0]);
      return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
      subject.checkRoles(Arrays.asList(roles));
      return;
View Full Code Here

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

    if (Logical.OR.equals(rrAnnotation.logical())) {
      // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
      boolean hasAtLeastOneRole = false;
      for (String role : roles) if (subject.hasRole(role)) hasAtLeastOneRole = true;
      // Cause the exception if none of the role match, note that the exception message will be a bit misleading
      if (!hasAtLeastOneRole) subject.checkRole(roles[0]);
    }
  }
}
View Full Code Here

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

    // so here is the problem, we clear the authz cache when ever config changes happen

    // now log the user in
    Subject subject1 = securitySystem.login(new UsernamePasswordToken(username, password));
    // check authz
    subject1.checkRole(DEFAULT_ROLE);

    // clear the cache
    KenaiRealm realm = (KenaiRealm) this.lookup(Realm.class, "kenai");
    realm.getAuthorizationCache().clear();
View Full Code Here

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

    // clear the cache
    KenaiRealm realm = (KenaiRealm) this.lookup(Realm.class, "kenai");
    realm.getAuthorizationCache().clear();

    // user should still have the role
    subject1.checkRole(DEFAULT_ROLE);

    // the user should be able to login again as well
    Subject subject2 = securitySystem.login(new UsernamePasswordToken(username, password));
    subject2.checkRole(DEFAULT_ROLE);
  }
View Full Code Here

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

    // user should still have the role
    subject1.checkRole(DEFAULT_ROLE);

    // the user should be able to login again as well
    Subject subject2 = securitySystem.login(new UsernamePasswordToken(username, password));
    subject2.checkRole(DEFAULT_ROLE);
  }
}
View Full Code Here

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

  @Override
  public void assertAuthorized() throws AuthorizationException {
    Subject subject = getSubject();
    //数据库权限
    if (jdbcRole != null) {
      subject.checkRole(jdbcRole);
      return;
    }
  }
}
View Full Code Here

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

    if (!(annotation instanceof RequiresRoles)) return;
    RequiresRoles rrAnnotation = (RequiresRoles) annotation;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
      subject.checkRole(roles[0]);
      return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
      subject.checkRoles(Arrays.asList(roles));
      return;
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.