Package org.apache.shiro.authc

Examples of org.apache.shiro.authc.AuthenticationToken


    @Test
    public void testBasic() {
        CredentialsMatcher matcher = (CredentialsMatcher) ClassUtils.newInstance(getMatcherClass());
        byte[] hashed = hash("password").getBytes();
        AuthenticationInfo account = new SimpleAuthenticationInfo("username", hashed, "realmName");
        AuthenticationToken token = new UsernamePasswordToken("username", "password");
        assertTrue(matcher.doCredentialsMatch(token, account));
    }
View Full Code Here


    @Test
    public void testDefaultConfig() {
        Subject subject = SecurityUtils.getSubject();

        AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
        subject.login(token);
        assertTrue(subject.isAuthenticated());
        assertTrue("guest".equals(subject.getPrincipal()));
        assertTrue(subject.hasRole("guest"));
View Full Code Here

    @Test
    public void testSubjectReuseAfterLogout() {

        Subject subject = SecurityUtils.getSubject();

        AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
        subject.login(token);
        assertTrue(subject.isAuthenticated());
        assertTrue("guest".equals(subject.getPrincipal()));
        assertTrue(subject.hasRole("guest"));
View Full Code Here

        sm.setRealm(new IniRealm(ini));
        SecurityUtils.setSecurityManager(sm);

        Subject subject = SecurityUtils.getSubject();

        AuthenticationToken token = new UsernamePasswordToken("guest", "guest");
        subject.login(token);
        subject.getSession().setAttribute("key", "value");
        assertTrue(subject.getSession().getAttribute("key").equals("value"));

        subject = SecurityUtils.getSubject();
View Full Code Here

public abstract class AuthenticatingFilter extends AuthenticationFilter {

    //TODO - complete JavaDoc

    protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
        AuthenticationToken token = createToken(request, response);
        if (token == null) {
            String msg = "createToken method implementation returned null. A valid non-null AuthenticationToken " +
                    "must be created in order to execute a login attempt.";
            throw new IllegalStateException(msg);
        }
View Full Code Here

  protected void login( LoginAccount account ){
    if( account == null || account.getLoginName() == null
        || account.getPassword() == null )
      return;
   
    AuthenticationToken token = new UsernamePasswordToken(
        account.getLoginName(),account.getPassword());
   
    SecurityUtils.getSubject().login(token);
   
    //记录Session
View Full Code Here

        jdbcRealm = new JdbcRealm();
    }

    @Override
    public boolean authenticate(String userName, Object credentials) throws UserStoreException {
        AuthenticationToken authenticationToken = new UsernamePasswordToken(userName,
                passwordDigester.getPasswordHashValue((String) credentials));

        AuthenticationInfo authenticationInfo;
        try {
View Full Code Here

    }

    if (isLoginAttempt(request, response)) {
      // NEXUS-5049: Check is this an attempt with "anonymous" user?
      // We do not allow logins with anonymous user if anon access is disabled
      final AuthenticationToken token = createToken(request, response);
      final String anonymousUsername = getSecuritySystem().getAnonymousUsername();
      final String loginUsername = token.getPrincipal().toString();
      if (!getSecuritySystem().isAnonymousAccessEnabled()
          && StringUtils.equals(anonymousUsername, loginUsername)) {
        getLogger().info(
            "Login attempt with username \"" + anonymousUsername
                + "\" (used for Anonymous Access) while Anonymous Access is disabled.");
View Full Code Here

   *
   * Otherwise will fallback to {@link NexusHttpAuthenticationFilter#isLoginAttempt(ServletRequest, ServletResponse)}
   */
  @Override
  protected boolean isLoginAttempt(ServletRequest request, ServletResponse response) {
    AuthenticationToken token = createAuthenticationToken(request, response);
    return token != null || super.isLoginAttempt(request, response);
  }
View Full Code Here

   * If none of them will return an authentication token will fallback to
   * {@link NexusHttpAuthenticationFilter#createToken(ServletRequest, ServletResponse)}
   */
  @Override
  protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
    AuthenticationToken token = createAuthenticationToken(request, response);
    if (token != null) {
      return token;
    }
    return super.createToken(request, response);
  }
View Full Code Here

TOP

Related Classes of org.apache.shiro.authc.AuthenticationToken

Copyright © 2018 www.massapicom. 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.