forked from apereo/cas
/
AbstractAttributeReleasePolicy.java
99 lines (83 loc) · 3.11 KB
/
AbstractAttributeReleasePolicy.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
/*
* Licensed to Jasig under one or more contributor license
* agreements. See the NOTICE file distributed with this work
* for additional information regarding copyright ownership.
* Jasig 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 the following location:
*
* 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.jasig.cas.services;
import java.util.Map;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.jasig.cas.authentication.principal.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Abstract release policy for attributes, provides common shared settings such as loggers and attribute filter config.
* Subclasses are to provide the behavior for attribute retrieval.
* @author Misagh Moayyed
* @since 4.1
*/
public abstract class AbstractAttributeReleasePolicy implements AttributeReleasePolicy {
private static final long serialVersionUID = 5325460875620586503L;
/** The logger. */
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
/** The attribute filter. */
private AttributeFilter attributeFilter = null;
@Override
public final void setAttributeFilter(final AttributeFilter filter) {
this.attributeFilter = filter;
}
/**
* Gets the attribute filter.
*
* @return the attribute filter
*/
protected final AttributeFilter getAttributeFilter() {
return this.attributeFilter;
}
@Override
public final Map<String, Object> getAttributes(final Principal p) {
final Map<String, Object> attributes = getAttributesInternal(p);
if (this.attributeFilter != null) {
return this.attributeFilter.filter(attributes);
}
return attributes;
}
/**
* Gets the attributes internally from the implementation.
*
* @param p the principal
* @return the attributes allowed for release
*/
protected abstract Map<String, Object> getAttributesInternal(final Principal p);
@Override
public int hashCode() {
return new HashCodeBuilder(13, 133).append(this.attributeFilter).toHashCode();
}
@Override
public boolean equals(final Object o) {
if (o == null) {
return false;
}
if (this == o) {
return true;
}
if (!(o instanceof AbstractAttributeReleasePolicy)) {
return false;
}
final AbstractAttributeReleasePolicy that = (AbstractAttributeReleasePolicy) o;
return new EqualsBuilder().append(this.attributeFilter, that.attributeFilter).isEquals();
}
}