Package org.apache.directory.shared.kerberos.flags

Examples of org.apache.directory.shared.kerberos.flags.TicketFlags


        EncTicketPart encTicketPart = new EncTicketPart();
        KerberosConfig config = authContext.getConfig();

        // The INITIAL flag indicates that a ticket was issued using the AS protocol.
        TicketFlags ticketFlags = new TicketFlags();
        encTicketPart.setFlags( ticketFlags );
        ticketFlags.setFlag( TicketFlag.INITIAL );

        // The PRE-AUTHENT flag indicates that the client used pre-authentication.
        if ( authContext.isPreAuthenticated() )
        {
            ticketFlags.setFlag( TicketFlag.PRE_AUTHENT );
        }

        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.FORWARDABLE ) )
        {
            if ( !config.isForwardableAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, because Forwadable is not allowed" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            ticketFlags.setFlag( TicketFlag.FORWARDABLE );
        }

        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.PROXIABLE ) )
        {
            if ( !config.isProxiableAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, because proxyiable is not allowed" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            ticketFlags.setFlag( TicketFlag.PROXIABLE );
        }

        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.ALLOW_POSTDATE ) )
        {
            if ( !config.isPostdatedAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, because Posdate is not allowed" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            ticketFlags.setFlag( TicketFlag.MAY_POSTDATE );
        }

        KdcOptions kdcOptions = request.getKdcReqBody().getKdcOptions();

        if ( kdcOptions.get( KdcOptions.RENEW )
            || kdcOptions.get( KdcOptions.VALIDATE )
            || kdcOptions.get( KdcOptions.PROXY )
            || kdcOptions.get( KdcOptions.FORWARDED )
            || kdcOptions.get( KdcOptions.ENC_TKT_IN_SKEY ) )
        {
            if ( LOG_KRB.isDebugEnabled() )
            {
                if ( kdcOptions.get( KdcOptions.RENEW ) )
                {
                    LOG_KRB.error( "Ticket cannot be generated, as it's a renew" );

                }

                if ( kdcOptions.get( KdcOptions.VALIDATE ) )
                {
                    LOG_KRB.error( "Ticket cannot be generated, as it's a validate" );

                }

                if ( kdcOptions.get( KdcOptions.PROXY ) )
                {
                    LOG_KRB.error( "Ticket cannot be generated, as it's a proxy" );

                }

                if ( kdcOptions.get( KdcOptions.FORWARDED ) )
                {
                    LOG_KRB.error( "Ticket cannot be generated, as it's forwarded" );

                }

                if ( kdcOptions.get( KdcOptions.ENC_TKT_IN_SKEY ) )
                {
                    LOG_KRB.error( "Ticket cannot be generated, as it's a user-to-user " );
                }
            }

            throw new KerberosException( ErrorType.KDC_ERR_BADOPTION );
        }

        EncryptionKey sessionKey = RandomKeyFactory.getRandomKey( authContext.getEncryptionType() );
        encTicketPart.setKey( sessionKey );

        encTicketPart.setCName( request.getKdcReqBody().getCName() );
        encTicketPart.setCRealm( request.getKdcReqBody().getRealm() );
        encTicketPart.setTransited( new TransitedEncoding() );
        String serverRealm = request.getKdcReqBody().getRealm();

        KerberosTime now = new KerberosTime();

        encTicketPart.setAuthTime( now );

        KerberosTime startTime = request.getKdcReqBody().getFrom();

        /*
         * "If the requested starttime is absent, indicates a time in the past,
         * or is within the window of acceptable clock skew for the KDC and the
         * POSTDATE option has not been specified, then the starttime of the
         * ticket is set to the authentication server's current time."
         */
        if ( startTime == null || startTime.lessThan( now ) || startTime.isInClockSkew( config.getAllowableClockSkew() )
            && !request.getKdcReqBody().getKdcOptions().get( KdcOptions.POSTDATED ) )
        {
            startTime = now;
        }

        /*
         * "If it indicates a time in the future beyond the acceptable clock skew,
         * but the POSTDATED option has not been specified, then the error
         * KDC_ERR_CANNOT_POSTDATE is returned."
         */
        if ( ( startTime != null ) && startTime.greaterThan( now )
            && !startTime.isInClockSkew( config.getAllowableClockSkew() )
            && !request.getKdcReqBody().getKdcOptions().get( KdcOptions.POSTDATED ) )
        {
            LOG_KRB.error( "Ticket cannot be generated, as it's in the future and the Postdated option is not set" );

            throw new KerberosException( ErrorType.KDC_ERR_CANNOT_POSTDATE );
        }

        /*
         * "Otherwise the requested starttime is checked against the policy of the
         * local realm and if the ticket's starttime is acceptable, it is set as
         * requested, and the INVALID flag is set in the new ticket."
         */
        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.POSTDATED ) )
        {
            if ( !config.isPostdatedAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, as Podated is not allowed" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            ticketFlags.setFlag( TicketFlag.POSTDATED );
            ticketFlags.setFlag( TicketFlag.INVALID );
            encTicketPart.setStartTime( startTime );
        }

        long till = 0;

        if ( request.getKdcReqBody().getTill().getTime() == 0 )
        {
            till = Long.MAX_VALUE;
        }
        else
        {
            till = request.getKdcReqBody().getTill().getTime();
        }

        /*
         * The end time is the minimum of (a) the requested till time or (b)
         * the start time plus maximum lifetime as configured in policy.
         */
        long endTime = Math.min( till, startTime.getTime() + config.getMaximumTicketLifetime() );
        KerberosTime kerberosEndTime = new KerberosTime( endTime );
        encTicketPart.setEndTime( kerberosEndTime );

        /*
         * "If the requested expiration time minus the starttime (as determined
         * above) is less than a site-determined minimum lifetime, an error
         * message with code KDC_ERR_NEVER_VALID is returned."
         */
        if ( kerberosEndTime.lessThan( startTime ) )
        {
            LOG_KRB.error( "Ticket cannot be generated, as the endTime is below the startTime" );
            throw new KerberosException( ErrorType.KDC_ERR_NEVER_VALID );
        }

        long ticketLifeTime = Math.abs( startTime.getTime() - kerberosEndTime.getTime() );

        if ( ticketLifeTime < config.getMinimumTicketLifetime() )
        {
            LOG_KRB.error( "Ticket cannot be generated, as the Lifetime is too small" );
            throw new KerberosException( ErrorType.KDC_ERR_NEVER_VALID );
        }

        /*
         * "If the requested expiration time for the ticket exceeds what was determined
         * as above, and if the 'RENEWABLE-OK' option was requested, then the 'RENEWABLE'
         * flag is set in the new ticket, and the renew-till value is set as if the
         * 'RENEWABLE' option were requested."
         */
        KerberosTime tempRtime = request.getKdcReqBody().getRTime();

        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.RENEWABLE_OK )
            && request.getKdcReqBody().getTill().greaterThan( kerberosEndTime ) )
        {
            if ( !config.isRenewableAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, as the renew date is exceeded" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            request.getKdcReqBody().getKdcOptions().set( KdcOptions.RENEWABLE );
            tempRtime = request.getKdcReqBody().getTill();
        }

        if ( request.getKdcReqBody().getKdcOptions().get( KdcOptions.RENEWABLE ) )
        {
            if ( !config.isRenewableAllowed() )
            {
                LOG_KRB.error( "Ticket cannot be generated, as Renewable is not allowed" );
                throw new KerberosException( ErrorType.KDC_ERR_POLICY );
            }

            ticketFlags.setFlag( TicketFlag.RENEWABLE );

            if ( tempRtime == null || tempRtime.isZero() )
            {
                tempRtime = KerberosTime.INFINITY;
            }
View Full Code Here


     */
    public void setFlag( TicketFlag flag )
    {
        if ( flags == null )
        {
            flags = new TicketFlags();
        }

        flags.setFlag( flag.getValue() );
    }
View Full Code Here

     */
    public void setFlag( TicketFlag flag )
    {
        if ( flags == null )
        {
            flags = new TicketFlags();
        }

        flags.setFlag( flag.getValue() );
    }
View Full Code Here

    public Ticket getTicket( KerberosPrincipal clientPrincipal, KerberosPrincipal serverPrincipal,
        EncryptionKey serverKey ) throws KerberosException, ParseException
    {
        EncTicketPart encTicketPart = new EncTicketPart();

        TicketFlags ticketFlags = new TicketFlags();
        ticketFlags.setFlag( TicketFlag.RENEWABLE );
        encTicketPart.setFlags( ticketFlags );

        EncryptionKey sessionKey = RandomKeyFactory.getRandomKey( EncryptionType.DES_CBC_MD5 );

        encTicketPart.setKey( sessionKey );
View Full Code Here

        pRealm = "prealm";
        // NOTE: we have to add each field manually cause order is important
        optionalFieldValueList.add( new FieldValueHolder( "pRealm", pRealm ) );

        ticketFlags = new TicketFlags( TicketFlag.INITIAL.getValue() );
        optionalFieldValueList.add( new FieldValueHolder( "ticketFlags", ticketFlags ) );

        authTime = new KerberosTime( new Date().getTime() );
        optionalFieldValueList.add( new FieldValueHolder( "authTime", authTime ) );
View Full Code Here

public class TicketFlagsTest
{
    @Test
    public void testTicketFlags()
    {
        TicketFlags flags = new TicketFlags();

        assertFalse( flags.isForwardable() );
        flags.setFlag( TicketFlag.FORWARDABLE );

        assertTrue( flags.isForwardable() );
        assertTrue( flags.toString().startsWith( TicketFlag.FORWARDABLE.toString() ) );

        assertFalse( flags.isRenewable() );
        flags.setFlag( TicketFlag.RENEWABLE );
        assertTrue( flags.isRenewable() );
        assertTrue( flags.isForwardable() );

        int flagValue = flags.getIntValue();
        assertEquals( 0x40800000, flagValue );

        flags.clearFlag( TicketFlag.FORWARDABLE );
        assertTrue( flags.isRenewable() );
        assertFalse( flags.isForwardable() );

        byte[] bytes = flags.getData();
        assertTrue( Arrays.equals( new byte[]
            { 0x00, 0x00, ( byte ) 0x80, 0x00, 0x00 }, bytes ) );
    }
View Full Code Here

{

    @Test
    public void testEmptyConstructor() throws Exception
    {
        TicketFlags tf = new TicketFlags();
        for ( TicketFlag t : TicketFlag.values() )
        {
            if ( !t.equals( TicketFlags.MAX_SIZE ) )
            {
                assertFalse( tf.isFlagSet( t ) );
            }
        }
        assertFalse( tf.isForwardable() );
        assertFalse( tf.isForwarded() );
        assertFalse( tf.isHwAuthent() );
        assertFalse( tf.isInitial() );
        assertFalse( tf.isInvalid() );
        assertFalse( tf.isMayPosdate() );
        assertFalse( tf.isOkAsDelegate() );
        assertFalse( tf.isPostdated() );
        assertFalse( tf.isPreAuth() );
        assertFalse( tf.isProxiable() );
        assertFalse( tf.isProxy() );
        assertFalse( tf.isRenewable() );
        assertFalse( tf.isReserved() );
        assertFalse( tf.isTransitedPolicyChecked() );
    }
View Full Code Here

    @Test
    public void testGivenIntConstructor() throws Exception
    {
        // Flags 1, 2, 4, 8 set
        TicketFlags tf = new TicketFlags( ( int ) ( Math.pow( 2, 31 - 1 ) + Math.pow( 2, 31 - 2 )
            + Math.pow( 2, 31 - 4 ) + Math.pow(
            2, 31 - 8 ) ) );
        assertFalse( tf.isReserved() ); // 0
        assertTrue( tf.isForwardable() ); // 1
        assertTrue( tf.isForwarded() ); // 2
        assertFalse( tf.isProxiable() ); // 3
        assertTrue( tf.isProxy() ); // 4
        assertFalse( tf.isMayPosdate() ); // 5
        assertFalse( tf.isPostdated() ); // 6
        assertFalse( tf.isInvalid() ); // 7
        assertTrue( tf.isRenewable() ); // 8
        assertFalse( tf.isInitial() ); // 9
        assertFalse( tf.isPreAuth() ); // 10
        assertFalse( tf.isHwAuthent() ); // 11
        assertFalse( tf.isTransitedPolicyChecked() ); // 12
        assertFalse( tf.isOkAsDelegate() ); // 13
    }
View Full Code Here

    @Test
    public void testGivenByteArrayConstructor() throws Exception
    {
        // Flags 1, 2, 4, 8 set
        TicketFlags tf = new TicketFlags(
            getBytes( ( int ) ( ( 1 << ( 31 - 1 ) ) |
                ( 1 << ( 31 - 2 ) ) |
                ( 1 << ( 31 - 4 ) ) |
            ( 1 << 31 - 8 ) ) ) );
        assertFalse( tf.isReserved() ); // 0
        assertTrue( tf.isForwardable() ); // 1
        assertTrue( tf.isForwarded() ); // 2
        assertFalse( tf.isProxiable() ); // 3
        assertTrue( tf.isProxy() ); // 4
        assertFalse( tf.isMayPosdate() ); // 5
        assertFalse( tf.isPostdated() ); // 6
        assertFalse( tf.isInvalid() ); // 7
        assertTrue( tf.isRenewable() ); // 8
        assertFalse( tf.isInitial() ); // 9
        assertFalse( tf.isPreAuth() ); // 10
        assertFalse( tf.isHwAuthent() ); // 11
        assertFalse( tf.isTransitedPolicyChecked() ); // 12
        assertFalse( tf.isOkAsDelegate() ); // 13

    }
View Full Code Here


    @Test
    public void testSetFlag() throws Exception
    {
        TicketFlags tf = new TicketFlags();

        for ( TicketFlag t : TicketFlag.values() )
        {
            if ( !t.equals( TicketFlag.MAX_VALUE ) )
            {
                tf.setFlag( t );
            }
        }

        assertTrue( tf.isReserved() ); // 0
        assertTrue( tf.isForwardable() ); // 1
        assertTrue( tf.isForwarded() ); // 2
        assertTrue( tf.isProxiable() ); // 3
        assertTrue( tf.isProxy() ); // 4
        assertTrue( tf.isMayPosdate() ); // 5
        assertTrue( tf.isPostdated() ); // 6
        assertTrue( tf.isInvalid() ); // 7
        assertTrue( tf.isRenewable() ); // 8
        assertTrue( tf.isInitial() ); // 9
        assertTrue( tf.isPreAuth() ); // 10
        assertTrue( tf.isHwAuthent() ); // 11
        assertTrue( tf.isTransitedPolicyChecked() ); // 12
        assertTrue( tf.isOkAsDelegate() ); // 13
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.kerberos.flags.TicketFlags

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.