directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbenn...@apache.org
Subject svn commit: r486187 [3/49] - in /directory/trunks/triplesec: ./ admin-api/ admin-api/src/ admin-api/src/main/ admin-api/src/main/java/ admin-api/src/main/java/org/ admin-api/src/main/java/org/safehaus/ admin-api/src/main/java/org/safehaus/triplesec/ ad...
Date Tue, 12 Dec 2006 15:24:14 GMT
Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/HauskeysUserModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/HauskeysUserModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/HauskeysUserModifier.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/HauskeysUserModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,668 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import org.safehaus.triplesec.admin.dao.HauskeysUserDao;
+
+
+public class HauskeysUserModifier implements Constants
+{
+    private final String id;
+    private final HauskeysUser archetype;
+    private final HauskeysUserDao dao;
+
+    private final SingleValuedField firstName;
+    private final SingleValuedField disabled;
+    private final SingleValuedField lastName;
+    private final SingleValuedField password;
+    private final SingleValuedField description;
+    private final SingleValuedField mobile;
+    private final SingleValuedField email;
+    private final SingleValuedField notifyBy;
+    private final SingleValuedField mobileCarrier;
+    private final SingleValuedField tokenPin;
+    private final SingleValuedField midletName;
+    private final SingleValuedField failuresInEpoch;
+    private final SingleValuedField activationKey;
+    private final SingleValuedField realm;
+    private final SingleValuedField secret;
+    private final SingleValuedField label;
+    private final SingleValuedField movingFactor;
+    
+    private final SingleValuedField address1;
+    private final SingleValuedField address2;
+    private final SingleValuedField city;
+    private final SingleValuedField stateProvRegion;
+    private final SingleValuedField zipPostalCode;
+    private final SingleValuedField country;
+    private final SingleValuedField company;
+
+    private boolean persisted = false;
+    
+    
+    // -----------------------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------------------
+
+    
+    public HauskeysUserModifier( HauskeysUserDao dao, HauskeysUser archetype )
+    {
+        this.id = archetype.getId();
+        this.dao = dao;
+        this.archetype = archetype;
+        this.firstName = new SingleValuedField( GIVENNAME_ID, archetype.getFirstName() );
+        this.lastName = new SingleValuedField( SURNAME_ID, archetype.getLastName() );
+        this.password = new SingleValuedField( PASSWORD_ID, archetype.getPassword() );
+        this.description = new SingleValuedField( DESCRIPTION_ID, archetype.getDescription() );
+        this.mobile = new SingleValuedField( MOBILE_ID, archetype.getMobile() );
+        this.email = new SingleValuedField( EMAIL_ID, archetype.getEmail() );
+        this.notifyBy = new SingleValuedField( NOTIFY_BY_ID, archetype.getNotifyBy() );
+        this.mobileCarrier = new SingleValuedField( MOBILE_CARRIER_ID, archetype.getMobileCarrier() );
+        this.tokenPin = new SingleValuedField( TOKEN_PIN_ID, archetype.getTokenPin() );
+        this.midletName = new SingleValuedField( MIDLE_NAME_ID, archetype.getMidletName() );
+        this.failuresInEpoch = new SingleValuedField( FAILURES_IN_EPOCH_ID, archetype.getFailuresInEpoch() );
+        this.activationKey = new SingleValuedField( ACTIVATION_KEY_ID, archetype.getActivationKey() );
+        this.realm = new SingleValuedField( REALM_ID, archetype.getRealm() );
+        this.secret = new SingleValuedField( SECRET_ID, archetype.getSecret() );
+        this.label = new SingleValuedField( LABEL_ID, archetype.getLabel() );
+        this.movingFactor = new SingleValuedField( MOVING_FACTOR_ID, archetype.getMovingFactor() );
+        this.address1 = new SingleValuedField( STREET_ID, archetype.getAddress1() );
+        this.address2 = new SingleValuedField( POSTAL_ADDRESS_ID, archetype.getAddress2() );
+        this.city = new SingleValuedField( LOCALITY_NAME_ID, archetype.getCity() );
+        this.stateProvRegion = new SingleValuedField( STATE_PROVINCE_ID, archetype.getStateProvRegion() );
+        this.zipPostalCode = new SingleValuedField( ZIP_POSTAL_CODE_ID, archetype.getZipPostalCode() );
+        this.country = new SingleValuedField( COUNTRY_ID, archetype.getCountry() );
+        this.company = new SingleValuedField( ORGANIZATION_ID, archetype.getCompany() );
+        this.disabled = new SingleValuedField( KRB5_DISABLED_ID, String.valueOf( archetype.isDisabled() ).toUpperCase() );
+    }
+
+
+    public HauskeysUserModifier( HauskeysUserDao dao, String id, String firstName, String lastName, 
+        String password )
+    {
+        this.id = id;
+        this.dao = dao;
+        this.archetype = null;
+        this.firstName = new SingleValuedField( GIVENNAME_ID, firstName );
+        this.lastName = new SingleValuedField( SURNAME_ID, lastName );
+        this.disabled = new SingleValuedField( KRB5_DISABLED_ID, "FALSE" );
+
+        this.password = new SingleValuedField( PASSWORD_ID, password );
+        this.description = new SingleValuedField( DESCRIPTION_ID, null );
+        this.mobile = new SingleValuedField( MOBILE_ID, null );
+        this.email = new SingleValuedField( EMAIL_ID, null );
+        this.notifyBy = new SingleValuedField( NOTIFY_BY_ID, null );
+        this.mobileCarrier = new SingleValuedField( MOBILE_CARRIER_ID, null );
+        this.tokenPin = new SingleValuedField( TOKEN_PIN_ID, null );
+        this.midletName = new SingleValuedField( MIDLE_NAME_ID, null );
+        this.failuresInEpoch = new SingleValuedField( FAILURES_IN_EPOCH_ID, null );
+        this.activationKey = new SingleValuedField( ACTIVATION_KEY_ID, null );
+        this.realm = new SingleValuedField( REALM_ID, null );
+        this.secret = new SingleValuedField( SECRET_ID, null );
+        this.label = new SingleValuedField( LABEL_ID, null );
+        this.movingFactor = new SingleValuedField( MOVING_FACTOR_ID, null );
+        this.address1 = new SingleValuedField( STREET_ID, null );
+        this.address2 = new SingleValuedField( POSTAL_ADDRESS_ID, null );
+        this.city = new SingleValuedField( LOCALITY_NAME_ID, null );
+        this.stateProvRegion = new SingleValuedField( STATE_PROVINCE_ID, null );
+        this.zipPostalCode = new SingleValuedField( ZIP_POSTAL_CODE_ID, null );
+        this.country = new SingleValuedField( COUNTRY_ID, null );
+        this.company = new SingleValuedField( ORGANIZATION_ID, null );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Mutators
+    // -----------------------------------------------------------------------
+
+    
+    public HauskeysUserModifier setAddress1( String address1 )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.address1.setValue( address1 );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setAddress2( String address2 )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.address2.setValue( address2 );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setCity( String city )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.city.setValue( city );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setStateProvRegion( String stateProvRegion )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.stateProvRegion.setValue( stateProvRegion );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setZipPostalCode( String zipPostalCode )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.zipPostalCode.setValue( zipPostalCode );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setCountry( String country )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.country.setValue( country );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setCompany( String company )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.company.setValue( company );
+        return this;
+    }
+    
+    
+    public HauskeysUserModifier setDisabled( boolean disabled )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.disabled.setValue( String.valueOf( disabled ).toUpperCase() );
+        return this;
+    }
+
+    
+    public HauskeysUserModifier setFirstName( String firstName )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.firstName.setValue( firstName );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setLastName( String lastName )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.lastName.setValue( lastName );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setPassword( String password )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.password.setValue( password );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setDescription( String description )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.description.setValue( description );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setMobile( String mobile )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.mobile.setValue( mobile );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setEmail( String email )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.email.setValue( email );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setNotifyBy( String notifyBy )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.notifyBy.setValue( notifyBy );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setMobileCarrier( String mobileCarrier )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.mobileCarrier.setValue( mobileCarrier );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setTokenPin( String tokenPin )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.tokenPin.setValue( tokenPin );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setMidletName( String midletName )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.midletName.setValue( midletName );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setFailuresInEpoch( String failuresInEpoch )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.failuresInEpoch.setValue( failuresInEpoch );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setActivationKey( String activationKey )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.activationKey.setValue( activationKey );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setRealm( String realm )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.realm.setValue( realm );
+        return this;
+    }
+    
+   
+    public HauskeysUserModifier setSecret( String secret )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.secret.setValue( secret );
+        return this;
+    }
+
+    
+    public HauskeysUserModifier setLabel( String label )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.label.setValue( label );
+        return this;
+    }
+
+    
+    public HauskeysUserModifier setMovingFactor( String movingFactor )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.movingFactor.setValue( movingFactor );
+        return this;
+    }
+
+    
+    // -----------------------------------------------------------------------
+    // Modifier Check Methods
+    // -----------------------------------------------------------------------
+
+    
+    public boolean isNewEntry()
+    {
+        return archetype == null;
+    }
+
+
+    public boolean isUpdatableEntry()
+    {
+        return archetype != null;
+    }
+    
+    
+    public boolean isValid()
+    {
+        return ! persisted;
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return 
+            disabled.isUpdateNeeded() ||
+            description.isUpdateNeeded() || 
+            firstName.isUpdateNeeded() || 
+            lastName.isUpdateNeeded() || 
+            password.isUpdateNeeded() ||
+            mobile.isUpdateNeeded() ||
+            email.isUpdateNeeded() ||
+            notifyBy.isUpdateNeeded() ||
+            mobileCarrier.isUpdateNeeded() ||
+            tokenPin.isUpdateNeeded() ||
+            midletName.isUpdateNeeded() ||
+            failuresInEpoch.isUpdateNeeded() ||
+            activationKey.isUpdateNeeded() ||
+            realm.isUpdateNeeded() ||
+            secret.isUpdateNeeded() ||
+            label.isUpdateNeeded() ||
+            movingFactor.isUpdateNeeded() ||
+            address1.isUpdateNeeded() ||
+            address2.isUpdateNeeded() ||
+            city.isUpdateNeeded() ||
+            stateProvRegion.isUpdateNeeded() ||
+            zipPostalCode.isUpdateNeeded() ||
+            country.isUpdateNeeded() ||
+            company.isUpdateNeeded();
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Modifier Methods
+    // -----------------------------------------------------------------------
+
+    
+    public HauskeysUser add() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        HauskeysUser user = dao.add( id, description.getCurrentValue(), firstName.getCurrentValue(),
+            lastName.getCurrentValue(), password.getCurrentValue(), mobile.getCurrentValue(), 
+            email.getCurrentValue(), notifyBy.getCurrentValue(), mobileCarrier.getCurrentValue(), 
+            tokenPin.getCurrentValue(), midletName.getCurrentValue(), failuresInEpoch.getCurrentValue(),
+            activationKey.getCurrentValue(), realm.getCurrentValue(), secret.getCurrentValue(), 
+            label.getCurrentValue(), movingFactor.getCurrentValue(), address1.getCurrentValue(), 
+            address2.getCurrentValue(), city.getCurrentValue(), stateProvRegion.getCurrentValue(), 
+            zipPostalCode.getCurrentValue(), country.getCurrentValue(), company.getCurrentValue(), 
+            parseBoolean( disabled.getCurrentValue().toLowerCase() ) );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public HauskeysUser rename( String newName ) throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( isUpdateNeeded() )
+        {
+            throw new ModificationLossException( id + " has been modified. " +
+                    "A rename operation will result in the loss of these modifications." );
+        }
+        
+        HauskeysUser user = dao.rename( newName, archetype );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public HauskeysUser modify() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        HauskeysUser user = dao.modify( archetype.getCreatorsName(), archetype.getCreateTimestamp(), id, 
+            description.getCurrentValue(), firstName.getCurrentValue(), lastName.getCurrentValue(), 
+            password.getCurrentValue(), mobile.getCurrentValue(), email.getCurrentValue(), 
+            notifyBy.getCurrentValue(), mobileCarrier.getCurrentValue(), tokenPin.getCurrentValue(), 
+            midletName.getCurrentValue(), failuresInEpoch.getCurrentValue(), activationKey.getCurrentValue(), 
+            realm.getCurrentValue(), secret.getCurrentValue(), label.getCurrentValue(), 
+            movingFactor.getCurrentValue(), address1.getCurrentValue(), 
+            address2.getCurrentValue(), city.getCurrentValue(), stateProvRegion.getCurrentValue(), 
+            zipPostalCode.getCurrentValue(), country.getCurrentValue(), company.getCurrentValue(), 
+            parseBoolean( disabled.getCurrentValue().toLowerCase() ), getModificationItems() );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public void delete() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        dao.delete( id );
+        persisted = true;
+    }
+
+    
+    private ModificationItem[] getModificationItems()
+    {
+        // new entries do not generate modification items
+        if ( isNewEntry() )
+        {
+            return EMPTY_MODS;
+        }
+
+        if ( isUpdateNeeded() )
+        {
+            List mods = new ArrayList();
+            if ( description.isUpdateNeeded() )
+            {
+                mods.add( description.getModificationItem() );
+            }
+            if ( firstName.isUpdateNeeded() )
+            {
+                mods.add( firstName.getModificationItem() );
+            }
+            if ( lastName.isUpdateNeeded() )
+            {
+                mods.add( lastName.getModificationItem() );
+            }
+            if ( password.isUpdateNeeded() )
+            {
+                mods.add( password.getModificationItem() );
+            }
+            if ( mobile.isUpdateNeeded() )
+            {
+                mods.add( mobile.getModificationItem() );
+            }
+            if ( email.isUpdateNeeded() )
+            {
+                mods.add( email.getModificationItem() );
+            }
+            if ( notifyBy.isUpdateNeeded() )
+            {
+                mods.add( notifyBy.getModificationItem() );
+            }
+            if ( mobileCarrier.isUpdateNeeded() )
+            {
+                mods.add( mobileCarrier.getModificationItem() );
+            }
+            if ( tokenPin.isUpdateNeeded() )
+            {
+                mods.add( tokenPin.getModificationItem() );
+            }
+            if ( midletName.isUpdateNeeded() )
+            {
+                mods.add( midletName.getModificationItem() );
+            }
+            if ( failuresInEpoch.isUpdateNeeded() )
+            {
+                mods.add( failuresInEpoch.getModificationItem() );
+            }
+            if ( activationKey.isUpdateNeeded() )
+            {
+                mods.add( activationKey.getModificationItem() );
+            }
+            if ( realm.isUpdateNeeded() )
+            {
+                mods.add( realm.getModificationItem() );
+            }
+            if ( secret.isUpdateNeeded() )
+            {
+                mods.add( secret.getModificationItem() );
+            }
+            if ( label.isUpdateNeeded() )
+            {
+                mods.add( label.getModificationItem() );
+            }
+            if ( movingFactor.isUpdateNeeded() )
+            {
+                mods.add( movingFactor.getModificationItem() );
+            }
+            if ( address1.isUpdateNeeded() )
+            {
+                mods.add( address1.getModificationItem() );
+            }
+            if ( address2.isUpdateNeeded() )
+            {
+                mods.add( address2.getModificationItem() );
+            }
+            if ( city.isUpdateNeeded() )
+            {
+                mods.add( city.getModificationItem() );
+            }
+            if ( stateProvRegion.isUpdateNeeded() )
+            {
+                mods.add( stateProvRegion.getModificationItem() );
+            }
+            if ( zipPostalCode.isUpdateNeeded() )
+            {
+                mods.add( zipPostalCode.getModificationItem() );
+            }
+            if ( country.isUpdateNeeded() )
+            {
+                mods.add( country.getModificationItem() );
+            }
+            if ( company.isUpdateNeeded() )
+            {
+                mods.add( company.getModificationItem() );
+            }
+            if ( disabled.isUpdateNeeded() )
+            {
+                mods.add( disabled.getModificationItem() );
+            }
+            
+            // if first or last name has changed modify the common name
+            if ( firstName.isUpdateNeeded() || lastName.isUpdateNeeded() )
+            {
+                mods.add( new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute( "cn", 
+                    firstName.getCurrentValue() + " " + lastName.getCurrentValue() ) ) );
+            }
+            
+            ModificationItem[] modArray = new ModificationItem[mods.size()];
+            return ( ModificationItem[] ) mods.toArray( modArray );
+        }
+        return EMPTY_MODS;
+    }
+
+    
+    private static boolean parseBoolean( String bool )
+    {
+        if ( bool.equals( "true" ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUser.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUser.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUser.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUser.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,158 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Date;
+
+import org.safehaus.triplesec.admin.dao.LocalUserDao;
+
+
+public class LocalUser extends User
+{
+    private final LocalUserDao dao;
+    private final String firstName;
+    private final String lastName;
+    private final String password;
+    private final String address1;
+    private final String address2;
+    private final String city;
+    private final String stateProvRegion;
+    private final String zipPostalCode;
+    private final String country;
+    private final String company;
+    private final String email;
+    
+    
+    public LocalUser( String creatorsName, Date createTimestamp, String modifiersName, 
+        Date modifyTimestamp, LocalUserDao dao, String id, String description, String firstName, 
+        String lastName, String password, String address1, String address2, String city, String stateProvRegion, 
+        String zipPostalCode, String country, String company, String email, boolean disabled )
+    {
+        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp, id, description, disabled );
+        this.dao = dao;
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.password = password;
+        
+        this.address1 = address1;
+        this.address2 = address2;
+        this.city = city;
+        this.stateProvRegion = stateProvRegion;
+        this.zipPostalCode = zipPostalCode;
+        this.country = country;
+        this.company = company;
+        this.email = email;
+    }
+
+
+    public LocalUser( String creatorsName, Date createTimestamp, LocalUserDao dao, String id, 
+        String description, String firstName, String lastName, String password, String address1, 
+        String address2, String city, String stateProvRegion, String zipPostalCode, String country, 
+        String company, String email, boolean disabled )
+    {
+        super( creatorsName, createTimestamp, id, description, disabled );
+        this.dao = dao;
+        this.firstName = firstName;
+        this.lastName = lastName;
+        this.password = password;
+        
+        this.address1 = address1;
+        this.address2 = address2;
+        this.city = city;
+        this.stateProvRegion = stateProvRegion;
+        this.zipPostalCode = zipPostalCode;
+        this.country = country;
+        this.company = company;
+        this.email = email;
+    }
+
+
+    public LocalUserModifier modifier()
+    {
+        return new LocalUserModifier( dao, this );
+    }
+
+
+    public String getFirstName()
+    {
+        return firstName;
+    }
+
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+
+    public String getLastName()
+    {
+        return lastName;
+    }
+
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+
+    public String getAddress1()
+    {
+        return address1;
+    }
+
+
+    public String getAddress2()
+    {
+        return address2;
+    }
+
+
+    public String getCity()
+    {
+        return city;
+    }
+
+
+    public String getStateProvRegion()
+    {
+        return stateProvRegion;
+    }
+
+
+    public String getZipPostalCode()
+    {
+        return zipPostalCode;
+    }
+
+
+    public String getCountry()
+    {
+        return country;
+    }
+
+
+    public String getCompany()
+    {
+        return company;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUserModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUserModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUserModifier.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/LocalUserModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,440 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.directory.ModificationItem;
+
+import org.safehaus.triplesec.admin.dao.LocalUserDao;
+
+
+public class LocalUserModifier implements Constants
+{
+    private final String id;
+    private final LocalUser archetype;
+    private final LocalUserDao dao;
+    private final SingleValuedField disabled;
+    private final SingleValuedField firstName;
+    private final SingleValuedField lastName;
+    private final SingleValuedField password;
+    private final SingleValuedField description;
+
+    private final SingleValuedField address1;
+    private final SingleValuedField address2;
+    private final SingleValuedField city;
+    private final SingleValuedField stateProvRegion;
+    private final SingleValuedField zipPostalCode;
+    private final SingleValuedField country;
+    private final SingleValuedField company;
+    private final SingleValuedField email;
+
+    private boolean persisted = false;
+    
+    // -----------------------------------------------------------------------
+    // Constructors
+    // -----------------------------------------------------------------------
+
+    
+    public LocalUserModifier( LocalUserDao dao, LocalUser archetype )
+    {
+        this.id = archetype.getId();
+        this.dao = dao;
+        this.archetype = archetype;
+        this.firstName = new SingleValuedField( GIVENNAME_ID, archetype.getFirstName() );
+        this.lastName = new SingleValuedField( SURNAME_ID, archetype.getLastName() );
+        this.password = new SingleValuedField( PASSWORD_ID, archetype.getPassword() );
+        this.description = new SingleValuedField( DESCRIPTION_ID, archetype.getDescription() );
+        this.disabled = new SingleValuedField( KRB5_DISABLED_ID, String.valueOf( archetype.isDisabled() ).toUpperCase() );
+        this.address1 = new SingleValuedField( STREET_ID, archetype.getAddress1() );
+        this.address2 = new SingleValuedField( POSTAL_ADDRESS_ID, archetype.getAddress2() );
+        this.city = new SingleValuedField( LOCALITY_NAME_ID, archetype.getCity() );
+        this.stateProvRegion = new SingleValuedField( STATE_PROVINCE_ID, archetype.getStateProvRegion() );
+        this.zipPostalCode = new SingleValuedField( ZIP_POSTAL_CODE_ID, archetype.getZipPostalCode() );
+        this.country = new SingleValuedField( COUNTRY_ID, archetype.getCountry() );
+        this.company = new SingleValuedField( ORGANIZATION_ID, archetype.getCompany() );
+        this.email = new SingleValuedField( EMAIL_ID, archetype.getEmail() );
+    }
+
+
+    public LocalUserModifier( LocalUserDao dao, String id, String firstName, String lastName, String password )
+    {
+        this.id = id;
+        this.dao = dao;
+        this.archetype = null;
+        this.firstName = new SingleValuedField( GIVENNAME_ID, firstName );
+        this.lastName = new SingleValuedField( SURNAME_ID, lastName );
+        this.password = new SingleValuedField( PASSWORD_ID, password );
+        this.description = new SingleValuedField( DESCRIPTION_ID, null );
+        this.disabled = new SingleValuedField( KRB5_DISABLED_ID, "FALSE" );
+        this.address1 = new SingleValuedField( STREET_ID, null );
+        this.address2 = new SingleValuedField( POSTAL_ADDRESS_ID, null );
+        this.city = new SingleValuedField( LOCALITY_NAME_ID, null );
+        this.stateProvRegion = new SingleValuedField( STATE_PROVINCE_ID, null );
+        this.zipPostalCode = new SingleValuedField( ZIP_POSTAL_CODE_ID, null );
+        this.country = new SingleValuedField( COUNTRY_ID, null );
+        this.company = new SingleValuedField( ORGANIZATION_ID, null );
+        this.email = new SingleValuedField( EMAIL_ID, null );
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Mutators
+    // -----------------------------------------------------------------------
+
+    
+    public LocalUserModifier setEmail( String email )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.email.setValue( email );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setAddress1( String address1 )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.address1.setValue( address1 );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setAddress2( String address2 )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.address2.setValue( address2 );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setCity( String city )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.city.setValue( city );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setStateProvRegion( String stateProvRegion )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.stateProvRegion.setValue( stateProvRegion );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setZipPostalCode( String zipPostalCode )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.zipPostalCode.setValue( zipPostalCode );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setCountry( String country )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.country.setValue( country );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setCompany( String company )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.company.setValue( company );
+        return this;
+    }
+    
+    
+    public LocalUserModifier setDisabled( boolean disabled )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.disabled.setValue( String.valueOf( disabled ).toUpperCase() );
+        return this;
+    }
+
+    
+    public LocalUserModifier setFirstName( String firstName )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.firstName.setValue( firstName );
+        return this;
+    }
+    
+   
+    public LocalUserModifier setLastName( String lastName )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.lastName.setValue( lastName );
+        return this;
+    }
+    
+   
+    public LocalUserModifier setPassword( String password )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.password.setValue( password );
+        return this;
+    }
+    
+   
+    public LocalUserModifier setDescription( String description )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.description.setValue( description );
+        return this;
+    }
+    
+   
+    // -----------------------------------------------------------------------
+    // Modifier Check Methods
+    // -----------------------------------------------------------------------
+
+    
+    public boolean isNewEntry()
+    {
+        return archetype == null;
+    }
+
+
+    public boolean isUpdatableEntry()
+    {
+        return archetype != null;
+    }
+    
+    
+    public boolean isValid()
+    {
+        return ! persisted;
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return 
+            description.isUpdateNeeded() || 
+            firstName.isUpdateNeeded() || 
+            lastName.isUpdateNeeded() || 
+            password.isUpdateNeeded() || 
+            disabled.isUpdateNeeded() ||
+            address1.isUpdateNeeded() ||
+            address2.isUpdateNeeded() ||
+            city.isUpdateNeeded() ||
+            stateProvRegion.isUpdateNeeded() ||
+            zipPostalCode.isUpdateNeeded() ||
+            country.isUpdateNeeded() ||
+            company.isUpdateNeeded() ||
+            email.isUpdateNeeded();
+            
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Modifier Methods
+    // -----------------------------------------------------------------------
+
+    
+    public LocalUser add() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        LocalUser user = dao.add( id, description.getCurrentValue(), firstName.getCurrentValue(), 
+            lastName.getCurrentValue(), password.getCurrentValue(), address1.getCurrentValue(), 
+            address2.getCurrentValue(), city.getCurrentValue(), stateProvRegion.getCurrentValue(), 
+            zipPostalCode.getCurrentValue(), country.getCurrentValue(), company.getCurrentValue(), 
+            email.getCurrentValue(), parseBoolean( disabled.getCurrentValue().toLowerCase() ) );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public LocalUser rename( String newName ) throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( isUpdateNeeded() )
+        {
+            throw new ModificationLossException( id + " has been modified. " +
+                    "A rename operation will result in the loss of these modifications." );
+        }
+        
+        LocalUser user = dao.rename( newName, archetype );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public LocalUser modify() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        LocalUser user = dao.modify( archetype.getCreatorsName(), archetype.getCreateTimestamp(), id, 
+            description.getCurrentValue(), password.getCurrentValue(), firstName.getCurrentValue(),  
+            lastName.getCurrentValue(), address1.getCurrentValue(), 
+            address2.getCurrentValue(), city.getCurrentValue(), stateProvRegion.getCurrentValue(), 
+            zipPostalCode.getCurrentValue(), country.getCurrentValue(), company.getCurrentValue(),
+            email.getCurrentValue(), parseBoolean( disabled.getCurrentValue().toLowerCase() ), 
+            getModificationItems() );
+        persisted = true;
+        return user;
+    }
+    
+    
+    public void delete() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        dao.delete( id );
+        persisted = true;
+    }
+
+    
+    private ModificationItem[] getModificationItems()
+    {
+        // new entries do not generate modification items
+        if ( isNewEntry() )
+        {
+            return EMPTY_MODS;
+        }
+
+        if ( isUpdateNeeded() )
+        {
+            List mods = new ArrayList();
+            if ( description.isUpdateNeeded() )
+            {
+                mods.add( description.getModificationItem() );
+            }
+            if ( firstName.isUpdateNeeded() )
+            {
+                mods.add( firstName.getModificationItem() );
+            }
+            if ( lastName.isUpdateNeeded() )
+            {
+                mods.add( lastName.getModificationItem() );
+            }
+            if ( password.isUpdateNeeded() )
+            {
+                mods.add( password.getModificationItem() );
+            }
+            if ( disabled.isUpdateNeeded() )
+            {
+                mods.add( disabled.getModificationItem() );
+            }
+            if ( address1.isUpdateNeeded() )
+            {
+                mods.add( address1.getModificationItem() );
+            }
+            if ( address2.isUpdateNeeded() )
+            {
+                mods.add( address2.getModificationItem() );
+            }
+            if ( city.isUpdateNeeded() )
+            {
+                mods.add( city.getModificationItem() );
+            }
+            if ( stateProvRegion.isUpdateNeeded() )
+            {
+                mods.add( stateProvRegion.getModificationItem() );
+            }
+            if ( zipPostalCode.isUpdateNeeded() )
+            {
+                mods.add( zipPostalCode.getModificationItem() );
+            }
+            if ( country.isUpdateNeeded() )
+            {
+                mods.add( country.getModificationItem() );
+            }
+            if ( company.isUpdateNeeded() )
+            {
+                mods.add( company.getModificationItem() );
+            }
+            if ( email.isUpdateNeeded() )
+            {
+                mods.add( email.getModificationItem() );
+            }
+            
+            ModificationItem[] modArray = new ModificationItem[mods.size()];
+            return ( ModificationItem[] ) mods.toArray( modArray );
+        }
+        return EMPTY_MODS;
+    }
+
+    
+    private static boolean parseBoolean( String bool )
+    {
+        if ( bool.equals( "true" ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ModificationLossException.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ModificationLossException.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ModificationLossException.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ModificationLossException.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+public class ModificationLossException extends RuntimeException
+{
+    private static final long serialVersionUID = 1L;
+
+    
+    public ModificationLossException( String msg )
+    {
+        super( msg );
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/MultiValuedField.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/MultiValuedField.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/MultiValuedField.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/MultiValuedField.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,148 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+
+public class MultiValuedField
+{
+    private final String id;
+    private final Set initial;
+    private Set added;
+    private Set deleted;
+    private Set current;
+
+    
+    public MultiValuedField( String id, Set initial )
+    {
+        this.id = id;
+        this.initial = Collections.unmodifiableSet( new HashSet( initial ) );
+        this.current = new HashSet( initial );
+        this.deleted = new HashSet();
+        this.added = new HashSet();
+    }
+
+
+    public boolean addValue( String value )
+    {
+        // if we have the value then exit and return false
+        if ( current.contains( value ) )
+        {
+            return false;
+        }
+
+        // if the value is not present but was deleted before then undelete it
+        if ( deleted.contains( value ) )
+        {
+            deleted.remove( value );
+        }
+        // if value was not deleted before then add to added
+        else
+        {
+            added.add( value );
+        }
+
+        return current.add( value );
+    }
+
+
+    public boolean removeValue( String value )
+    {
+        // if we don't have the value then return false
+        if ( ! current.contains( value ) )
+        {
+            return false;
+        }
+        
+        // if the value was added before then we unadd it 
+        if ( added.contains( value ) )
+        {
+            added.remove( value );
+        }
+        // if the value was not added before then we delete it
+        else
+        {
+            deleted.add( value );
+        }
+        
+        return current.remove( value );
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return added.size() + deleted.size() > 0;
+    }
+    
+    
+    public Set getInitialValues()
+    {
+        return initial;
+    }
+    
+    
+    public Set getCurrentValues()
+    {
+        return Collections.unmodifiableSet( current );
+    }
+    
+    
+    public ModificationItem getModificationItem()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return null;
+        }
+        
+        BasicAttribute attr = new BasicAttribute( id );
+        if ( added.size() == 0 && deleted.size() > 0 )
+        {
+            for ( Iterator ii = deleted.iterator(); ii.hasNext(); /**/ )
+            {
+                attr.add( ii.next() );
+            }
+            return new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+        }
+        
+        if ( added.size() > 0 && deleted.size() == 0 )
+        {
+            for ( Iterator ii = added.iterator(); ii.hasNext(); /**/ )
+            {
+                attr.add( ii.next() );
+            }
+            return new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
+        }
+        
+        for ( Iterator ii = current.iterator(); ii.hasNext(); /**/ )
+        {
+            attr.add( ii.next() );
+        }
+        return new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/NoSuchEntryException.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/NoSuchEntryException.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/NoSuchEntryException.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/NoSuchEntryException.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+public class NoSuchEntryException extends DataAccessException
+{
+    private static final long serialVersionUID = -1343441322242678678L;
+
+    
+    public NoSuchEntryException()
+    {
+        super();
+    }
+
+
+    public NoSuchEntryException( String msg )
+    {
+        super( msg );
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Permission.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Permission.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Permission.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Permission.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Date;
+
+import org.safehaus.triplesec.admin.dao.PermissionDao;
+
+
+public class Permission extends AdministeredEntity
+{
+    private final String description;
+    private final String name;
+    private final String applicationName;
+    private final PermissionDao dao;
+
+    
+    public Permission( String creatorsName, Date createTimestamp, PermissionDao dao, String applicationName, String name, String description )
+    {
+        this( creatorsName, createTimestamp, null, null, dao, applicationName, name, description );
+    }
+    
+    
+    public Permission( String creatorsName, Date createTimestamp, String modifiersName, 
+        Date modifyTimestamp, PermissionDao dao, String applicationName, String name, String description )
+    {
+        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp );
+        this.dao = dao;
+        this.applicationName = applicationName;
+        this.name = name;
+        this.description = description;
+    }
+        
+    
+    public String getDescription()
+    {
+        return description;
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+    
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+    
+    
+    public PermissionModifier modifier()
+    {
+        return new PermissionModifier( dao, this );
+    }
+    
+    
+    public String toString()
+    {
+        return name;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionDeniedException.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionDeniedException.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionDeniedException.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionDeniedException.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,38 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+public class PermissionDeniedException extends DataAccessException
+{
+    private static final long serialVersionUID = 2970896053000775404L;
+
+    
+    public PermissionDeniedException()
+    {
+        super();
+    }
+    
+    
+    public PermissionDeniedException( String msg )
+    {
+        super( msg );
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionModifier.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/PermissionModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,165 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import javax.naming.directory.ModificationItem;
+
+import org.safehaus.triplesec.admin.dao.PermissionDao;
+
+
+
+public class PermissionModifier implements Constants
+{
+    private final PermissionDao dao;
+    private final Permission archetype;
+    private final String applicationName;
+    private final String name;
+    private final SingleValuedField description;
+    private boolean persisted = false;
+    
+    
+    public PermissionModifier( PermissionDao dao, String applicationName, String name )
+    {
+        this.dao = dao;
+        description = new SingleValuedField( DESCRIPTION_ID, null );
+        archetype = null;
+        this.name = name;
+        this.applicationName = applicationName;
+    }
+    
+    
+    public PermissionModifier( PermissionDao dao, Permission archetype )
+    {
+        this.dao = dao;
+        this.description = new SingleValuedField( DESCRIPTION_ID, archetype.getDescription() );
+        this.archetype = archetype;
+        name = archetype.getName();
+        applicationName = archetype.getApplicationName();
+    }
+    
+    
+    public PermissionModifier setDescription( String description )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        this.description.setValue( description );
+        return this;
+    }
+
+    
+    private ModificationItem[] getModificationItems()
+    {
+        // new entries do not generate modification items
+        if ( isNewEntry() )
+        {
+            return EMPTY_MODS;
+        }
+        
+        if ( description.isUpdateNeeded() )
+        {
+            return new ModificationItem[] { description.getModificationItem() };
+        }
+        
+        return EMPTY_MODS;
+    }
+
+
+    public boolean isNewEntry()
+    {
+        return archetype == null;
+    }
+
+
+    public boolean isUpdatableEntry()
+    {
+        return archetype != null;
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return description.isUpdateNeeded();
+    }
+    
+    
+    public boolean isValid()
+    {
+        return !persisted;
+    }
+    
+    
+    public Permission add() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Permission perm = dao.add( applicationName, name, description.getCurrentValue() );
+        persisted = true;
+        return perm;
+    }
+    
+    
+    public Permission rename( String newPermName ) throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( isUpdateNeeded() )
+        {
+            throw new ModificationLossException( name + " has been modified. " +
+                    "A rename operation will result in the loss of these modifications." );
+        }
+        
+        Permission perm = dao.rename( newPermName, archetype );
+        persisted = true;
+        return perm;
+    }
+    
+    
+    public Permission modify() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Permission perm = dao.modify( archetype.getCreatorsName(), archetype.getCreateTimestamp(), applicationName, 
+            name, description.getCurrentValue(), getModificationItems() );
+        persisted = true;
+        return perm;
+    }
+    
+    
+    public void delete() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        dao.delete( applicationName, name );
+        persisted = true;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Profile.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Profile.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Profile.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Profile.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,127 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.safehaus.triplesec.admin.dao.ProfileDao;
+
+
+public class Profile extends AdministeredEntity
+{
+    private final ProfileDao dao;
+    private final Set grants;
+    private final Set denials;
+    private final Set roles;
+    private final String id;
+    private final String user;
+    private final String description;
+    private final String applicationName;
+    private final boolean disabled;
+    
+    
+    public Profile( String creatorsName, Date createTimestamp, ProfileDao dao, String applicationName, 
+        String id, String user, String description, Set grants, Set denials, Set roles )
+    {
+        this( creatorsName, createTimestamp, null, null, dao, applicationName, id, 
+            user, description, grants, denials, roles, false );
+    }
+    
+    
+    public Profile( String creatorsName, Date createTimestamp, String modifiersName, Date modifyTimestamp, 
+        ProfileDao dao, String applicationName, String id, String user, String description, 
+        Set grants, Set denials, Set roles, boolean disabled )
+    {
+        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp );
+        this.dao = dao;
+        this.applicationName = applicationName;
+        this.id = id;
+        this.user = user;
+        this.grants = new HashSet( grants );
+        this.denials = new HashSet( denials );
+        this.roles = new HashSet( roles );
+        this.description = description;
+        this.disabled = disabled;
+    }
+    
+    
+    public Set getGrants()
+    {
+        return Collections.unmodifiableSet( grants );
+    }
+
+
+    public Set getDenials()
+    {
+        return Collections.unmodifiableSet( denials );
+    }
+
+
+    public Set getRoles()
+    {
+        return Collections.unmodifiableSet( roles );
+    }
+
+
+    public String getId()
+    {
+        return id;
+    }
+
+
+    public String getUser()
+    {
+        return user;
+    }
+
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+    
+    
+    public ProfileModifier modifier()
+    {
+        return new ProfileModifier( dao, this );
+    }
+
+    
+    public boolean isDisabled()
+    {
+        return disabled;
+    }
+    
+    
+    public String toString()
+    {
+        return id;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ProfileModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ProfileModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ProfileModifier.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ProfileModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,343 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.naming.directory.ModificationItem;
+
+import org.safehaus.triplesec.admin.dao.ProfileDao;
+
+
+
+public class ProfileModifier implements Constants
+{
+    private final ProfileDao dao;
+    private final Profile archetype;
+    private final String id;
+    private final String applicationName;
+    private final SingleValuedField description;
+    private final SingleValuedField user;
+    private final SingleValuedField disabled;
+    private final MultiValuedField grants;
+    private final MultiValuedField denials;
+    private final MultiValuedField roles;
+    
+    private boolean persisted = false;
+    
+    
+    public ProfileModifier( ProfileDao dao, String applicationName, String id, String user )
+    {
+        archetype = null;
+        this.dao = dao;
+        this.applicationName = applicationName;
+        this.id = id;
+        this.description = new SingleValuedField( DESCRIPTION_ID, null );
+        this.user = new SingleValuedField( USER_ID, user );
+        this.grants = new MultiValuedField( GRANTS_ID, Collections.EMPTY_SET );
+        this.denials = new MultiValuedField( DENIALS_ID, Collections.EMPTY_SET );
+        this.roles = new MultiValuedField( ROLES_ID, Collections.EMPTY_SET );
+        this.disabled = new SingleValuedField( SAFEHAUS_DISABLED_ID, "FALSE" );
+    }
+    
+    
+    public ProfileModifier( ProfileDao dao, Profile archetype )
+    {
+        this.dao = dao;
+        this.archetype = archetype;
+        this.applicationName = archetype.getApplicationName();
+        this.id = archetype.getId();
+        this.description = new SingleValuedField( DESCRIPTION_ID, archetype.getDescription() );
+        this.disabled = new SingleValuedField( SAFEHAUS_DISABLED_ID, String.valueOf( archetype.isDisabled() ) );
+        this.user = new SingleValuedField( USER_ID, archetype.getUser() );
+        this.grants = new MultiValuedField( GRANTS_ID, archetype.getGrants() );
+        this.denials = new MultiValuedField( DENIALS_ID, archetype.getDenials() );
+        this.roles = new MultiValuedField( ROLES_ID, archetype.getRoles() );
+    }
+    
+    
+    public ProfileModifier setDisable( boolean disabled )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.disabled.setValue( String.valueOf( disabled ).toUpperCase() );
+        return this;
+    }
+    
+    
+    public ProfileModifier setDescription( String description )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.description.setValue( description );
+        return this;
+    }
+
+    
+    public ProfileModifier setUser( String user )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        this.user.setValue( user );
+        return this;
+    }
+
+    
+    public ProfileModifier addGrant( String grant )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( grant == null )
+        {
+            return this;
+        }
+
+        grants.addValue( grant );
+        return this;
+    }
+    
+    
+    public ProfileModifier removeGrant( String grant )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( grant == null )
+        {
+            return this;
+        }
+
+        grants.removeValue( grant );
+        return this;
+    }
+    
+    
+    public ProfileModifier addDenial( String denial )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( denial == null )
+        {
+            return this;
+        }
+
+        denials.addValue( denial );
+        return this;
+    }
+    
+    
+    public ProfileModifier removeDenial( String denial )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( denial == null )
+        {
+            return this;
+        }
+
+        denials.removeValue( denial );
+        return this;
+    }
+    
+    
+    public ProfileModifier addRole( String role )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( role == null )
+        {
+            return this;
+        }
+
+        roles.addValue( role );
+        return this;
+    }
+    
+    
+    public ProfileModifier removeRole( String role )
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+
+        if ( role == null )
+        {
+            return this;
+        }
+
+        roles.removeValue( role );
+        return this;
+    }
+    
+    
+    private ModificationItem[] getModificationItems()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return EMPTY_MODS;
+        }
+        
+        List mods = new ArrayList();
+        if ( grants.isUpdateNeeded() )
+        {
+            mods.add( grants.getModificationItem() );
+        }
+        if ( denials.isUpdateNeeded() )
+        {
+            mods.add( denials.getModificationItem() );
+        }
+        if ( roles.isUpdateNeeded() )
+        {
+            mods.add( roles.getModificationItem() );
+        }
+        if ( description.isUpdateNeeded() )
+        {
+            mods.add( description.getModificationItem() );
+        }
+        if ( disabled.isUpdateNeeded() )
+        {
+            mods.add( disabled.getModificationItem() );
+        }
+        if ( user.isUpdateNeeded() )
+        {
+            mods.add( user.getModificationItem() );
+        }
+        
+        return ( ModificationItem[] ) mods.toArray( EMPTY_MODS );
+    }
+
+
+    public boolean isNewEntry()
+    {
+        return archetype == null;
+    }
+
+
+    public boolean isUpdatableEntry()
+    {
+        return archetype != null;
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return disabled.isUpdateNeeded() || grants.isUpdateNeeded() || denials.isUpdateNeeded() || 
+            roles.isUpdateNeeded() || description.isUpdateNeeded() || user.isUpdateNeeded();
+    }
+
+
+    public boolean isValid()
+    {
+        return !persisted;
+    }
+    
+    
+    public Profile add() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Profile profile = dao.add( applicationName, id, user.getCurrentValue(), description.getCurrentValue(), 
+            grants.getCurrentValues(), denials.getCurrentValues(), roles.getCurrentValues() );
+        persisted = true;
+        return profile;
+    }
+
+    
+    public Profile rename( String newProfileId ) throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        
+        if ( isUpdateNeeded() )
+        {
+            throw new ModificationLossException( id + " has been modified. " +
+                    "A rename operation will result in the loss of these modifications." );
+        }
+        
+        Profile profile = dao.rename( newProfileId, archetype );
+        persisted = true;
+        return profile;
+    }
+    
+    
+    public Profile modify() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Profile profile = dao.modify( archetype.getCreatorsName(), archetype.getCreateTimestamp(), 
+            applicationName, id, user.getCurrentValue(), description.getCurrentValue(), 
+            grants.getCurrentValues(), denials.getCurrentValues(), roles.getCurrentValues(), 
+            parseBoolean( disabled.getCurrentValue().toLowerCase() ), getModificationItems() );
+        persisted = true;
+        return profile;
+    }
+    
+    
+    public void delete() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        dao.delete( applicationName, id );
+        persisted = true;
+    }
+
+    
+    private static boolean parseBoolean( String bool )
+    {
+        if ( bool.equals( "true" ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ReadOnlyIterator.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ReadOnlyIterator.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ReadOnlyIterator.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/ReadOnlyIterator.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Iterator;
+
+
+public class ReadOnlyIterator implements Iterator
+{
+    private final Iterator underlying;
+
+
+    ReadOnlyIterator(Iterator underlying)
+    {
+        this.underlying = underlying;
+    }
+
+
+    public boolean hasNext()
+    {
+        return underlying.hasNext();
+    }
+
+
+    public Object next()
+    {
+        return underlying.next();
+    }
+
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException( "Try obtaining an iterator from a modifier." );
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Role.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Role.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Role.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/Role.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,93 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.safehaus.triplesec.admin.dao.RoleDao;
+
+
+public class Role extends AdministeredEntity
+{
+    private final RoleDao dao;
+    private final String applicationName;
+    private final String name;
+    private final Set grants;
+    private final String description;
+
+    
+    public Role( String creatorsName, Date createTimestamp, RoleDao dao, String applicationName, 
+        String name, String description, Set grants )
+    {
+        this( creatorsName, createTimestamp, null, null, dao, applicationName, name, description, grants );
+    }
+    
+    
+    public Role( String creatorsName, Date createTimestamp, String modifiersName, Date modifyTimestamp, 
+        RoleDao dao, String applicationName, String name, String description, Set grants )
+    {
+        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp );
+        this.dao = dao;
+        this.applicationName = applicationName;
+        this.name = name;
+        this.description = description;
+        this.grants = new HashSet( grants );
+    }
+
+
+    public Set getGrants()
+    {
+        return Collections.unmodifiableSet( grants );
+    }
+
+
+    public String getName()
+    {
+        return name;
+    }
+
+
+    public String getDescription()
+    {
+        return description;
+    }
+
+
+    public String getApplicationName()
+    {
+        return applicationName;
+    }
+    
+    
+    public RoleModifier modifier()
+    {
+        return new RoleModifier( dao, this );
+    }
+    
+    
+    public String toString()
+    {
+        return name;
+    }
+}

Added: directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/RoleModifier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/RoleModifier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/RoleModifier.java (added)
+++ directory/trunks/triplesec/admin-api/src/main/java/org/safehaus/triplesec/admin/RoleModifier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,201 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin;
+
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.naming.directory.ModificationItem;
+
+import org.safehaus.triplesec.admin.dao.RoleDao;
+
+
+
+public class RoleModifier implements Constants
+{
+    private final Role archetype;
+    private final RoleDao dao;
+    private final String name;
+    private final String applicationName;
+    private SingleValuedField description;
+    private MultiValuedField grants;
+    private boolean persisted = false;
+    
+    
+    public RoleModifier( RoleDao dao, String applicationName, String name )
+    {
+        archetype = null;
+        this.dao = dao;
+        this.applicationName = applicationName;
+        this.name = name;
+        this.description = new SingleValuedField( DESCRIPTION_ID, null );
+        this.grants = new MultiValuedField( GRANTS_ID, Collections.EMPTY_SET );
+    }
+    
+    
+    public RoleModifier( RoleDao dao, Role archetype )
+    {
+        this.dao = dao;
+        this.archetype = archetype;
+        this.applicationName = archetype.getApplicationName();
+        this.name = archetype.getName();
+        this.description = new SingleValuedField( DESCRIPTION_ID, archetype.getDescription() );
+        this.grants = new MultiValuedField( GRANTS_ID, archetype.getGrants() );
+    }
+    
+    
+    public RoleModifier setDescription( String description )
+    {
+        this.description.setValue( description );
+        return this;
+    }
+
+    
+    public RoleModifier addGrant( String grant )
+    {
+        if ( grant == null )
+        {
+            return this;
+        }
+
+        grants.addValue( grant );
+        return this;
+    }
+    
+    
+    public RoleModifier removeGrant( String grant )
+    {
+        if ( grant == null )
+        {
+            return this;
+        }
+
+        grants.removeValue( grant );
+        return this;
+    }
+    
+    
+    public Role getArchetype()
+    {
+        return archetype;
+    }
+    
+    
+    private ModificationItem[] getModificationItems()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return EMPTY_MODS;
+        }
+        
+        List mods = new ArrayList();
+        if ( grants.isUpdateNeeded() )
+        {
+            mods.add( grants.getModificationItem() );
+        }
+        if ( description.isUpdateNeeded() )
+        {
+            mods.add( description.getModificationItem() );
+        }
+        
+        return ( ModificationItem[] ) mods.toArray( EMPTY_MODS );
+    }
+
+
+    public boolean isNewEntry()
+    {
+        return archetype == null;
+    }
+
+
+    public boolean isUpdatableEntry()
+    {
+        return archetype != null;
+    }
+    
+    
+    public boolean isUpdateNeeded()
+    {
+        return grants.isUpdateNeeded() || description.isUpdateNeeded();
+    }
+    
+    
+    public boolean isValid()
+    {
+        return !persisted;
+    }
+    
+    
+    public Role add() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Role role = dao.add( applicationName, name, description.getCurrentValue(), grants.getCurrentValues() );
+        persisted = true;
+        return role;
+    }
+
+    
+    public Role rename( String newName ) throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        
+        if ( isUpdateNeeded() )
+        {
+            throw new ModificationLossException( name + " has been modified. " +
+                    "A rename operation will result in the loss of these modifications." );
+        }
+        
+        Role role = dao.rename( newName, archetype );
+        persisted = true;
+        return role;
+    }
+    
+    
+    public Role modify() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        Role role = dao.modify( archetype.getCreatorsName(), archetype.getCreateTimestamp(), applicationName, 
+            name, description.getCurrentValue(), grants.getCurrentValues(), getModificationItems() );
+        persisted = true;
+        return role;
+    }
+    
+    
+    public void delete() throws DataAccessException
+    {
+        if ( persisted )
+        {
+            throw new IllegalStateException( INVALID_MSG );
+        }
+        dao.delete( applicationName, name );
+        persisted = true;
+    }
+}



Mime
View raw message