16 changed files with 334 additions and 116 deletions
@ -0,0 +1,93 @@ |
|||||||
|
package org.springframework.security.openid; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.springframework.util.Assert; |
||||||
|
|
||||||
|
/** |
||||||
|
* Represents an OpenID subject identity attribute. |
||||||
|
* <p> |
||||||
|
* Can be used for configuring the <tt>OpenID4JavaConsumer</tt> with the attributes which should be requested during a |
||||||
|
* fetch request, or to hold values for an attribute which are returned during the authentication process. |
||||||
|
* |
||||||
|
* @author Luke Taylor |
||||||
|
* @version $Id$ |
||||||
|
* @since 3.0 |
||||||
|
*/ |
||||||
|
public class OpenIDAttribute { |
||||||
|
private final String name; |
||||||
|
private final String typeIdentifier; |
||||||
|
private boolean required = false; |
||||||
|
private int count = 1; |
||||||
|
|
||||||
|
private final List<String> values; |
||||||
|
|
||||||
|
public OpenIDAttribute(String name, String type) { |
||||||
|
this.name = name; |
||||||
|
this.typeIdentifier = type; |
||||||
|
this.values = null; |
||||||
|
} |
||||||
|
|
||||||
|
public OpenIDAttribute(String name, String type, List<String> values) { |
||||||
|
Assert.notEmpty(values); |
||||||
|
this.name = name; |
||||||
|
this.typeIdentifier = type; |
||||||
|
this.values = values; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The attribute name |
||||||
|
*/ |
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The attribute type Identifier (a URI). |
||||||
|
*/ |
||||||
|
public String getType() { |
||||||
|
return typeIdentifier; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The "required" flag for the attribute when used with an authentication request. Defaults to "false". |
||||||
|
*/ |
||||||
|
public boolean isRequired() { |
||||||
|
return required; |
||||||
|
} |
||||||
|
|
||||||
|
public void setRequired(boolean required) { |
||||||
|
this.required = required; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The requested count for the attribute when it is used as part of an authentication |
||||||
|
* request. Defaults to 1. |
||||||
|
*/ |
||||||
|
public int getCount() { |
||||||
|
return count; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCount(int count) { |
||||||
|
this.count = count; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* The values obtained from an attribute exchange. |
||||||
|
*/ |
||||||
|
public List<String> getValues() { |
||||||
|
Assert.notNull(values, "Cannot read values from an authentication request attribute"); |
||||||
|
return values; |
||||||
|
} |
||||||
|
|
||||||
|
public String toString() { |
||||||
|
StringBuilder result = new StringBuilder("["); |
||||||
|
result.append(name); |
||||||
|
if (values != null) { |
||||||
|
result.append(":"); |
||||||
|
result.append(values.toString()); |
||||||
|
} |
||||||
|
result.append("]"); |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
} |
||||||
@ -1,38 +0,0 @@ |
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
||||||
* |
|
||||||
* Licensed 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.springframework.security.openid; |
|
||||||
|
|
||||||
import org.springframework.security.openid.OpenIDAuthenticationStatus; |
|
||||||
import org.springframework.security.openid.OpenIDAuthenticationToken; |
|
||||||
|
|
||||||
import junit.framework.TestCase; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author Ray Krueger |
|
||||||
*/ |
|
||||||
public class OpenIDAuthenticationTokenTests extends TestCase { |
|
||||||
|
|
||||||
public void test() throws Exception { |
|
||||||
OpenIDAuthenticationToken token = newToken(); |
|
||||||
assertEquals(token, newToken()); |
|
||||||
} |
|
||||||
|
|
||||||
private OpenIDAuthenticationToken newToken() { |
|
||||||
return new OpenIDAuthenticationToken( |
|
||||||
OpenIDAuthenticationStatus.SUCCESS, |
|
||||||
"http://raykrueger.blogspot.com/", |
|
||||||
"what is this for anyway?"); |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue