org.apache.directory.api.util.DateUtils Java Examples

The following examples show how to use org.apache.directory.api.util.DateUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PasswordUtil.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * checks if the given password's change time is older than the max age 
 *
 * @param pwdChangedZtime time when the password was last changed
 * @param pwdMaxAgeSec the max age value in seconds
 * @param timeProvider The TimeProvider instance to use
 * @return true if expired, false otherwise
 */
public static boolean isPwdExpired( String pwdChangedZtime, int pwdMaxAgeSec, TimeProvider timeProvider )
{
    Date pwdChangeDate = DateUtils.getDate( pwdChangedZtime );

    //DIRSERVER-1735
    long time = pwdMaxAgeSec * 1000L;
    time += pwdChangeDate.getTime();

    Date expiryDate = DateUtils.getDate( DateUtils.getGeneralizedTime( time ) );
    Date now = DateUtils.getDate( DateUtils.getGeneralizedTime( timeProvider ) );

    boolean expired = false;

    if ( expiryDate.equals( now ) || expiryDate.before( now ) )
    {
        expired = true;
    }

    return expired;
}
 
Example #2
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a Schema to an Entry
 * 
 * @param schema The Schema to convert
 * @param schemaManager The SchemaManager
 * @return An Entry containing the converted Schema
 * @throws LdapException If the conversion failed
 */
public Entry convert( Schema schema, SchemaManager schemaManager ) throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SCHEMA_OC );
    entry.put( SchemaConstants.CN_AT, schema.getSchemaName() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );

    if ( schema.isDisabled() )
    {
        entry.put( MetaSchemaConstants.M_DISABLED_AT, "TRUE" );
    }

    String[] dependencies = schema.getDependencies();

    if ( dependencies != null && dependencies.length > 0 )
    {
        Attribute attr = new DefaultAttribute(
            schemaManager.getAttributeType( MetaSchemaConstants.M_DEPENDENCIES_AT ) );

        for ( String dependency : dependencies )
        {
            attr.add( dependency );
        }

        entry.put( attr );
    }

    return entry;
}
 
Example #3
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a SyntaxChecker instance into an Entry
 *
 * @param syntaxChecker The SyntaxChecker to convert
 * @param schema The schema containing this SyntaxChecker
 * @param schemaManager The SchemaManager
 * @return An Entry containing the converted SyntaxChecker
 */
public Entry convert( SyntaxChecker syntaxChecker, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_CHECKER_OC );
    entry.put( MetaSchemaConstants.M_OID_AT, syntaxChecker.getOid() );
    entry.put( MetaSchemaConstants.M_FQCN_AT, syntaxChecker.getClass().getName() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );

    return entry;
}
 
Example #4
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a Syntax instance into an Entry
 *
 * @param syntax The LdapSytax to convert
 * @param schema The schema containing this Syntax
 * @param schemaManager The SchemaManager
 * @return And entry defining a LdapSyntax
 * @throws LdapException If the conversion failed
 */
public Entry convert( LdapSyntax syntax, Schema schema, SchemaManager schemaManager ) throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_SYNTAX_OC );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    injectCommon( syntax, entry, schemaManager );

    return entry;
}
 
Example #5
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a Normalizer instance into an Entry
 *
 * @param oid The Normalizer's OID
 * @param normalizer The Normalizer to convert
 * @param schema The schema containing this Normalizer
 * @param schemaManager The SchemaManager
 * @return An Entry defining a Normalizer
 */
public Entry convert( String oid, Normalizer normalizer, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_NORMALIZER_OC );
    entry.put( MetaSchemaConstants.M_OID_AT, oid );
    entry.put( MetaSchemaConstants.M_FQCN_AT, normalizer.getClass().getName() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #6
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a LdapComparator instance into an Entry
 *
 * @param oid The LdapComparator's OID
 * @param comparator The LdapComparator to convert
 * @param schema The schema containing this Comparator
 * @param schemaManager The SchemaManager
 * @return An Entry defining a LdapComparator
 */
public Entry convert( String oid, LdapComparator<? super Object> comparator, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_COMPARATOR_OC );
    entry.put( MetaSchemaConstants.M_OID_AT, oid );
    entry.put( MetaSchemaConstants.M_FQCN_AT, comparator.getClass().getName() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #7
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a MatchingRule into an Entry
 * 
 * @param matchingRule The MatchingRule to convert
 * @param schema The schema containing this ObjectClass
 * @param schemaManager The SchemaManager
 * @return The converted MatchingRule
 * @throws LdapException If the conversion failed
 */
public Entry convert( MatchingRule matchingRule, Schema schema, SchemaManager schemaManager )
    throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_MATCHING_RULE_OC );
    entry.put( MetaSchemaConstants.M_SYNTAX_AT, matchingRule.getSyntaxOid() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    injectCommon( matchingRule, entry, schemaManager );
    
    return entry;
}
 
Example #8
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a MatchingRuleUse into an Entry
 *
 * @param matchingRuleUse The MatchingRuleUse to convert
 * @param schema The schema containing this MatchingRuleUse
 * @param schemaManager The SchemaManager
 * @return The converted MatchingRuleUse
 */
public Entry convert( MatchingRuleUse matchingRuleUse, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #9
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a DitStructureRule into an Entry
 *
 * @param ditStructureRule The DitStructureRule to convert
 * @param schema The schema containing this DitStructureRule
 * @param schemaManager The SchemaManager
 * @return The converted DitStructureRule
 */
public Entry convert( DitStructureRule ditStructureRule, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #10
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a DitContentRule into an Entry
 *
 * @param dITContentRule The DitContentRule to convert
 * @param schema The schema containing this DitContentRule
 * @param schemaManager The SchemaManager
 * @return The converted DitContentRule
 */
public Entry convert( DitContentRule dITContentRule, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #11
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * Converts a NameForm into an Entry
 *
 * @param nameForm The NameForm to convert
 * @param schema The schema containing this NameForm
 * @param schemaManager The SchemaManager
 * @return The converted NameForm
 */
public Entry convert( NameForm nameForm, Schema schema, SchemaManager schemaManager )
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, "" );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );
    
    return entry;
}
 
Example #12
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * <pre>
 *    objectclass ( 1.3.6.1.4.1.18060.0.4.0.3.3
 *       NAME 'metaAttributeType'
 *       DESC 'meta definition of the AttributeType object'
 *       SUP metaTop
 *       STRUCTURAL
 *       MUST ( m-name $ m-syntax )
 *       MAY ( m-supAttributeType $ m-obsolete $ m-equality $ m-ordering $
 *             m-substr $ m-singleValue $ m-collective $ m-noUserModification $
 *             m-usage $ m-extensionAttributeType )
 *    )
 * </pre>
 * 
 * @param attributeType The AttributeType to convert
 * @param schema The schema containing this AttributeType
 * @param schemaManager The SchemaManager
 * @return The converted AttributeType 
 * @throws LdapException If the conversion failed
 */
public Entry convert( AttributeType attributeType, Schema schema, SchemaManager schemaManager ) throws LdapException
{
    Entry entry = new DefaultEntry( schemaManager );

    entry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, MetaSchemaConstants.META_ATTRIBUTE_TYPE_OC );
    entry.put( MetaSchemaConstants.M_COLLECTIVE_AT, getBoolean( attributeType.isCollective() ) );
    entry.put( MetaSchemaConstants.M_NO_USER_MODIFICATION_AT, getBoolean( !attributeType.isUserModifiable() ) );
    entry.put( MetaSchemaConstants.M_SINGLE_VALUE_AT, getBoolean( attributeType.isSingleValued() ) );
    entry.put( MetaSchemaConstants.M_USAGE_AT, attributeType.getUsage().toString() );
    entry.put( SchemaConstants.CREATORS_NAME_AT, schema.getOwner() );
    entry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime( timeProvider ) );

    injectCommon( attributeType, entry, schemaManager );

    String superiorOid = attributeType.getSuperiorOid();

    if ( superiorOid != null )
    {
        entry.put( MetaSchemaConstants.M_SUP_ATTRIBUTE_TYPE_AT, superiorOid );
    }

    if ( attributeType.getEqualityOid() != null )
    {
        entry.put( MetaSchemaConstants.M_EQUALITY_AT, attributeType.getEqualityOid() );
    }

    if ( attributeType.getSubstringOid() != null )
    {
        entry.put( MetaSchemaConstants.M_SUBSTR_AT, attributeType.getSubstringOid() );
    }

    if ( attributeType.getOrderingOid() != null )
    {
        entry.put( MetaSchemaConstants.M_ORDERING_AT, attributeType.getOrderingOid() );
    }

    if ( attributeType.getSyntaxOid() != null )
    {
        entry.put( MetaSchemaConstants.M_SYNTAX_AT, attributeType.getSyntaxOid() );
    }

    return entry;
}
 
Example #13
Source File: TUtil.java    From directory-fortress-core with Apache License 2.0 3 votes vote down vote up
/**
 * Convert from raw ldap generalized time format to {@link java.util.Date}.
 * to decode the string.
 *
 * @param inputString containing raw ldap generalized time formatted string.
 * @return converted to {@link java.util.Date}.
 */
public static java.util.Date decodeGeneralizedTime(String inputString) throws ParseException
{
    java.util.Date aDate;
    aDate = DateUtils.getDate( inputString );
    return aDate;
}
 
Example #14
Source File: TUtil.java    From directory-fortress-core with Apache License 2.0 3 votes vote down vote up
/**
 * Convert from java date {@link java.util.Date} format to raw ldap generalized time format.
 * to encode the string.
 *
 * @param date reference to standard java date.
 * @return converted to standardized ldap generalized time format.
 */
public static String encodeGeneralizedTime(java.util.Date date)
{
    String szTime;
    szTime = DateUtils.getGeneralizedTime( date );
    return szTime;
}