Package org.jasig.cas.support.spnego.authentication.principal

Examples of org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentials


public class SpnegoCredentialsTests extends TestCase {

   
    public void testToStringWithNoPrincipal() {
        final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {});
       
        assertTrue(credentials.toString().contains("unknown"));
    }
View Full Code Here


       
        assertTrue(credentials.toString().contains("unknown"));
    }
   
    public void testToStringWithPrincipal() {
        final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {});
        final Principal principal = new SimplePrincipal("test");
        credentials.setPrincipal(principal);
        assertEquals("test", credentials.toString());
    }
View Full Code Here

  private SpnegoCredentials spnegoCredentials;

  protected void setUp() throws Exception {
    this.resolver = new SpnegoCredentialsToPrincipalResolver();
    this.spnegoCredentials = new SpnegoCredentials(new byte[] { 0, 1, 2 });
  }
View Full Code Here

    protected void setUp() throws Exception {
        this.authenticationHandler = new JCIFSSpnegoAuthenticationHandler();
    }

    public void testSuccessfulAuthenticationWithDomainName() throws AuthenticationException {
        final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2});
        this.authenticationHandler.setPrincipalWithDomainName(true);
        this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(true));
        assertTrue(this.authenticationHandler.authenticate(credentials));
        assertEquals("test", credentials.getPrincipal().getId());
        assertNotNull(credentials.getNextToken());
    }
View Full Code Here

        assertEquals("test", credentials.getPrincipal().getId());
        assertNotNull(credentials.getNextToken());
    }

    public void testSuccessfulAuthenticationWithoutDomainName() throws AuthenticationException {
        final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2});
        this.authenticationHandler.setPrincipalWithDomainName(false);
        this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(true));
        assertTrue(this.authenticationHandler.authenticate(credentials));
        assertEquals("test", credentials.getPrincipal().getId());
        assertNotNull(credentials.getNextToken());
    }
View Full Code Here

        assertEquals("test", credentials.getPrincipal().getId());
        assertNotNull(credentials.getNextToken());
    }

    public void testUnsuccessfulAuthentication() {
        final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2});
        this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(false));
        try {
            this.authenticationHandler.authenticate(credentials);
            fail("An AuthenticationException should have been thrown");
        } catch (AuthenticationException e) {
            assertNull(credentials.getNextToken());
            assertNull(credentials.getPrincipal());
        }
    }
View Full Code Here

        }
    }

    public void testSupports() {
        assertFalse(this.authenticationHandler.supports(null));
        assertTrue(this.authenticationHandler.supports(new SpnegoCredentials(new byte[] {0, 1, 2})));
        assertFalse(this.authenticationHandler.supports(new UsernamePasswordCredentials()));
    }
View Full Code Here

            final byte[] token = Base64.decode(authorizationHeader
                .substring(this.messageBeginPrefix.length()));
            if (logger.isDebugEnabled()) {
                logger.debug("Obtained token: " + new String(token));
            }
            return new SpnegoCredentials(token);
        }

        return null;
    }
View Full Code Here

            return;
        }

        final HttpServletResponse response = WebUtils
            .getHttpServletResponse(context);
        final SpnegoCredentials spnegoCredentials = (SpnegoCredentials) credentials;
        final byte[] nextToken = spnegoCredentials.getNextToken();
        if (nextToken != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Obtained output token: " + new String(nextToken));
            }
            response.setHeader(SpnegoConstants.HEADER_AUTHENTICATE, (this.ntlm
                ? SpnegoConstants.NTLM : SpnegoConstants.NEGOTIATE)
                + " " + Base64.encode(nextToken));
        } else {
            logger.debug("Unable to obtain the output token required.");
        }

        if (spnegoCredentials.getPrincipal() == null) {
            logger.debug("Setting HTTP Status to 401");
            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        }
    }
View Full Code Here

     */
    private boolean isNTLMallowed = false;

    protected boolean doAuthentication(final Credentials credentials)
        throws AuthenticationException {
        final SpnegoCredentials spnegoCredentials = (SpnegoCredentials) credentials;
        Principal principal;
        byte[] nextToken;
        try {
            // proceed authentication using jcifs
            synchronized (this) {
                this.authentication.reset();
                this.authentication.process(spnegoCredentials.getInitToken());
                principal = this.authentication.getPrincipal();
                nextToken = this.authentication.getNextToken();
            }
        } catch (jcifs.spnego.AuthenticationException e) {
            throw new BadCredentialsAuthenticationException(e);
        }
        // evaluate jcifs response
        if (nextToken != null) {
            logger.debug("Setting nextToken in credentials");
            spnegoCredentials.setNextToken(nextToken);
        } else {
            logger.debug("nextToken is null");
        }

        if (principal != null) {
            if (spnegoCredentials.isNtlm()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("NTLM Credentials is valid for user ["
                        + principal.getName() + "]");
                }
                spnegoCredentials.setPrincipal(getSimplePrincipal(principal
                    .getName(), true));
                return this.isNTLMallowed;
            }
            // else => kerberos
            if (logger.isDebugEnabled()) {
                logger.debug("Kerberos Credentials is valid for user ["
                    + principal.getName() + "]");
            }
            spnegoCredentials.setPrincipal(getSimplePrincipal(principal
                .getName(), false));
            return true;

        }

View Full Code Here

TOP

Related Classes of org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentials

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.