Package org.apache.shiro.authc

Examples of org.apache.shiro.authc.AuthenticationToken


    @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

        HttpServletResponse response = createMock(HttpServletResponse.class);
       
        replay(request);
        replay(response);
       
    AuthenticationToken token = testFilter.createToken(request, response);
    assertNotNull(token);
    assertTrue("Token is not a username and password token.", token instanceof UsernamePasswordToken);
    assertEquals("", token.getPrincipal());
   
    verify(request);
    verify(response);
    }
View Full Code Here

        HttpServletResponse response = createMock(HttpServletResponse.class);
       
        replay(request);
        replay(response);
       
    AuthenticationToken token = testFilter.createToken(request, response);
    assertNotNull(token);
    assertTrue("Token is not a username and password token.", token instanceof UsernamePasswordToken);
    assertEquals("", token.getPrincipal());
   
    verify(request);
    verify(response);
    }
View Full Code Here

        HttpServletResponse response = createMock(HttpServletResponse.class);
       
        replay(request);
        replay(response);
       
    AuthenticationToken token = testFilter.createToken(request, response);
    assertNotNull(token);
    assertTrue("Token is not a username and password token.", token instanceof UsernamePasswordToken);
   
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    assertEquals("pedro", upToken.getUsername());
View Full Code Here

    public String resolveHost() {
        String host = getHost();

        if (host == null) {
            //check to see if there is an AuthenticationToken from which to retrieve it:
            AuthenticationToken token = getAuthenticationToken();
            if (token instanceof HostAuthenticationToken) {
                host = ((HostAuthenticationToken) token).getHost();
            }
        }
View Full Code Here

@ApplicationScoped
public class AuthenticationService {

    public boolean reauthenticate(String password) {
        UserPrincipal principal = (UserPrincipal) SecurityUtils.getSubject().getPrincipal();
        AuthenticationToken token = new UsernamePasswordToken(principal.getUserName(), password);
        boolean result = true;
        try {
            SecurityUtils.getSecurityManager().authenticate(token);
        } catch (AuthenticationException e) {
            result = false;
View Full Code Here

    public AuthenticationSession authenticate(final AuthenticationRequest request, final String code) {
        RealmSecurityManager securityManager = getSecurityManager();
        if(securityManager == null) {
            return null;
        }
        final AuthenticationToken token = asAuthenticationToken(request);
       
        Subject currentUser = SecurityUtils.getSubject();
        if(currentUser.isAuthenticated()) {
            // TODO: verify the code passed in that this session is still alive?
           
View Full Code Here

        this.realm.setGroupRolesMap(Collections.singletonMap("Users", ROLE_NAME));
    }

    @Test
    public void testValidUsernamePassword() {
        AuthenticationToken token = new UsernamePasswordToken(getCurrentUserName(), "somePassword");
        AuthenticationInfo authcInfo = this.realm.getAuthenticationInfo(token);
        PrincipalCollection principals = authcInfo.getPrincipals();
        assertFalse(principals.isEmpty());
        Object primaryPrincipal = principals.getPrimaryPrincipal();
        assertNotNull(primaryPrincipal);
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.