/
ScimGroupMember.java
129 lines (100 loc) · 3.51 KB
/
ScimGroupMember.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2016] Pivotal Software, Inc. All Rights Reserved.
*
* This product is licensed to you under the Apache License, Version 2.0 (the "License").
* You may not use this product except in compliance with the License.
*
* This product includes a number of subcomponents with
* separate copyright notices and license terms. Your use of these
* subcomponents is subject to the terms and conditions of the
* subcomponent's license, as noted in the LICENSE file.
*******************************************************************************/
package org.cloudfoundry.identity.uaa.scim;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.cloudfoundry.identity.uaa.constants.OriginKeys;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScimGroupMember<TEntity extends ScimCore> {
public TEntity getEntity() {
return entity;
}
public void setEntity(TEntity entity) {
this.entity = entity;
}
public ScimGroupMember() {
}
public ScimGroupMember(String memberId) {
this(memberId, Type.USER);
}
public ScimGroupMember(TEntity entity) {
this(entity.getId(), getEntityType(entity));
}
public ScimGroupMember(String memberId, Type type) {
this.memberId = memberId;
this.type = type;
}
@JsonProperty("value")
private String memberId;
private String origin = OriginKeys.UAA;
private String operation;
@JsonInclude(JsonInclude.Include.NON_NULL)
public enum Type {
USER, GROUP
}
private Type type;
private TEntity entity;
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
@Override
public String toString() {
return String.format("(memberId: %s, type: %s, origin:%s)", getMemberId(), getType(), getOrigin());
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
//don't allow null values
if (origin==null) {
throw new NullPointerException();
}
this.origin = origin;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ScimGroupMember member = (ScimGroupMember) o;
if (getMemberId() != null ? !getMemberId().equals(member.getMemberId()) : member.getMemberId() != null) return false;
return getType() == member.getType();
}
@Override
public int hashCode() {
int result = getMemberId() != null ? getMemberId().hashCode() : 0;
result = 31 * result + (getOrigin() != null ? getOrigin().hashCode() : 0);
result = 31 * result + (getType() != null ? getType().hashCode() : 0);
return result;
}
private static Type getEntityType(ScimCore entity) {
Type type = null;
if(entity instanceof ScimGroup) { type = Type.GROUP; }
else if(entity instanceof ScimUser) { type = Type.USER; }
return type;
}
}