Skip to content

Commit 9dd4bc2

Browse files
committed
ng-storage updates
misc fixes
1 parent ceb9337 commit 9dd4bc2

14 files changed

+197
-253
lines changed

server/src/main/java/password/pwm/bean/UserIdentity.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,12 @@ public LdapProfile getLdapProfile( final Configuration configuration )
7777
{
7878
return null;
7979
}
80-
if ( configuration.getLdapProfiles().containsKey( this.getLdapProfileID() ) )
81-
{
82-
return configuration.getLdapProfiles().get( this.getLdapProfileID() );
83-
}
84-
else
85-
{
86-
return null;
87-
}
80+
return configuration.getLdapProfiles().getOrDefault( this.getLdapProfileID(), null );
8881
}
8982

9083
public String toString( )
9184
{
92-
return "UserIdentity" + JsonUtil.serialize( this );
85+
return toDisplayString();
9386
}
9487

9588
public String toObfuscatedKey( final PwmApplication pwmApplication )

server/src/main/java/password/pwm/config/stored/NGStorageEngineImpl.java

Lines changed: 0 additions & 143 deletions
This file was deleted.

server/src/main/java/password/pwm/config/stored/StorageEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import password.pwm.bean.UserIdentity;
2626
import password.pwm.config.StoredValue;
2727

28-
interface StorageEngine
28+
public interface StorageEngine
2929
{
3030
StoredValue read( StoredConfigReference storedConfigReference );
3131

server/src/main/java/password/pwm/config/stored/StoredConfigReferenceBean.java

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@
2222

2323
package password.pwm.config.stored;
2424

25+
import lombok.Value;
26+
2527
import java.io.Serializable;
2628

27-
class StoredConfigReferenceBean implements StoredConfigReference, Serializable, Comparable
29+
@Value
30+
public class StoredConfigReferenceBean implements StoredConfigReference, Serializable, Comparable
2831
{
2932
private RecordType recordType;
3033
private String recordID;
3134
private String profileID;
3235

33-
StoredConfigReferenceBean( final RecordType type, final String recordID, final String profileID )
36+
public StoredConfigReferenceBean( final RecordType type, final String recordID, final String profileID )
3437
{
3538
if ( type == null )
3639
{
@@ -47,36 +50,6 @@ class StoredConfigReferenceBean implements StoredConfigReference, Serializable,
4750
this.profileID = profileID;
4851
}
4952

50-
public RecordType getRecordType( )
51-
{
52-
return recordType;
53-
}
54-
55-
public String getRecordID( )
56-
{
57-
return recordID;
58-
}
59-
60-
@Override
61-
public String getProfileID( )
62-
{
63-
return profileID;
64-
}
65-
66-
@Override
67-
public boolean equals( final Object o )
68-
{
69-
return o != null
70-
&& o instanceof StoredConfigReference
71-
&& toString().equals( o.toString() );
72-
73-
}
74-
75-
@Override
76-
public int hashCode( )
77-
{
78-
return toString().hashCode();
79-
}
8053

8154
@Override
8255
public String toString( )

server/src/main/java/password/pwm/config/stored/ValueMetaData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222

2323
package password.pwm.config.stored;
2424

25+
import lombok.Builder;
2526
import lombok.Value;
2627
import password.pwm.bean.UserIdentity;
2728

2829
import java.io.Serializable;
2930
import java.time.Instant;
3031

3132
@Value
33+
@Builder( toBuilder = true )
3234
public class ValueMetaData implements Serializable
3335
{
3436
private Instant modifyDate;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Password Management Servlets (PWM)
3+
* http://www.pwm-project.org
4+
*
5+
* Copyright (c) 2006-2009 Novell, Inc.
6+
* Copyright (c) 2009-2018 The PWM Project
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+
*/
22+
23+
package password.pwm.config.stored.ng;
24+
25+
import password.pwm.bean.UserIdentity;
26+
import password.pwm.config.StoredValue;
27+
import password.pwm.config.stored.StoredConfigReference;
28+
import password.pwm.config.stored.ValueMetaData;
29+
30+
import java.time.Instant;
31+
import java.util.HashMap;
32+
import java.util.Map;
33+
34+
class NGStorageEngineImpl
35+
{
36+
private final Map<StoredConfigReference, StoredValue> storedValues = new HashMap<>();
37+
private final Map<StoredConfigReference, ValueMetaData> metaValues = new HashMap<>();
38+
39+
NGStorageEngineImpl()
40+
{
41+
}
42+
43+
NGStorageEngineImpl(
44+
final Map<StoredConfigReference, StoredValue> storedValues,
45+
final Map<StoredConfigReference, ValueMetaData> metaValues
46+
)
47+
{
48+
this.storedValues.putAll( storedValues );
49+
this.metaValues.putAll( metaValues );
50+
}
51+
52+
StoredValue read( final StoredConfigReference storedConfigReference )
53+
{
54+
return storedValues.get( storedConfigReference );
55+
}
56+
57+
ValueMetaData readMetaData( final StoredConfigReference storedConfigReference )
58+
{
59+
return metaValues.get( storedConfigReference );
60+
}
61+
62+
void writeMetaData( final StoredConfigReference storedConfigReference, final ValueMetaData valueMetaData )
63+
{
64+
metaValues.put( storedConfigReference, valueMetaData );
65+
}
66+
67+
void write( final StoredConfigReference reference, final StoredValue value, final UserIdentity userIdentity )
68+
{
69+
if ( reference != null )
70+
{
71+
if ( value != null )
72+
{
73+
storedValues.put( reference, value );
74+
}
75+
76+
updateUserIdentity( reference, userIdentity );
77+
}
78+
}
79+
80+
void reset( final StoredConfigReference reference, final UserIdentity userIdentity )
81+
{
82+
if ( reference != null )
83+
{
84+
storedValues.remove( reference );
85+
updateUserIdentity( reference, userIdentity );
86+
}
87+
}
88+
89+
private void updateUserIdentity(
90+
final StoredConfigReference reference,
91+
final UserIdentity userIdentity
92+
)
93+
{
94+
metaValues.put(
95+
reference,
96+
ValueMetaData.builder().modifyDate( Instant.now() )
97+
.userIdentity( userIdentity )
98+
.build() );
99+
100+
}
101+
}

0 commit comments

Comments
 (0)