-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
207 changed files
with
9,559 additions
and
4,170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
common/src/main/java/org/cloudfoundry/identity/uaa/ExternalIdentityProviderDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.cloudfoundry.identity.uaa; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/******************************************************************************* | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2015] Pivotal Software, Inc. All Rights Reserved. | ||
* <p> | ||
* 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. | ||
* <p> | ||
* 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. | ||
*******************************************************************************/ | ||
public class ExternalIdentityProviderDefinition extends AbstractIdentityProviderDefinition { | ||
public static final String GROUP_ATTRIBUTE_NAME = "external_groups"; //can be a string or a list of strings | ||
public static final String EMAIL_ATTRIBUTE_NAME = "email"; //can be a string | ||
public static final String GIVEN_NAME_ATTRIBUTE_NAME = "given_name"; //can be a string | ||
public static final String FAMILY_NAME_ATTRIBUTE_NAME = "family_name"; //can be a string | ||
public static final String PHONE_NUMBER_ATTRIBUTE_NAME = "phone_number"; //can be a string | ||
public static final String USER_ATTRIBUTE_PREFIX = "user.attribute."; | ||
|
||
public static final String EXTERNAL_GROUPS_WHITELIST = "externalGroupsWhitelist"; | ||
public static final String ATTRIBUTE_MAPPINGS = "attributeMappings"; | ||
|
||
private List<String> externalGroupsWhitelist = new LinkedList<>(); | ||
private Map<String, Object> attributeMappings = new HashMap<>(); | ||
|
||
public List<String> getExternalGroupsWhitelist() { | ||
return Collections.unmodifiableList(externalGroupsWhitelist); | ||
} | ||
|
||
public void setExternalGroupsWhitelist(List<String> externalGroupsWhitelist) { | ||
this.externalGroupsWhitelist = new LinkedList<>(externalGroupsWhitelist!=null ? externalGroupsWhitelist : Collections.EMPTY_LIST); | ||
} | ||
|
||
@JsonIgnore | ||
public void addWhiteListedGroup(String group) { | ||
this.externalGroupsWhitelist.add(group); | ||
} | ||
|
||
public void setAttributeMappings(Map<String, Object> attributeMappings) { | ||
this.attributeMappings = new HashMap<>(attributeMappings!=null?attributeMappings:Collections.EMPTY_MAP); | ||
} | ||
|
||
public Map<String, Object> getAttributeMappings() { | ||
return Collections.unmodifiableMap(attributeMappings); | ||
} | ||
|
||
@JsonIgnore | ||
public void addAttributeMapping(String key, Object value) { | ||
attributeMappings.put(key, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...main/java/org/cloudfoundry/identity/uaa/authentication/UaaAuthenticationDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* ***************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2015] 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.authentication; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static java.util.Collections.EMPTY_LIST; | ||
import static java.util.Collections.EMPTY_MAP; | ||
import static java.util.Collections.EMPTY_SET; | ||
|
||
public class UaaAuthenticationDeserializer extends JsonDeserializer<UaaAuthentication> implements UaaAuthenticationJsonBase { | ||
@Override | ||
public UaaAuthentication deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { | ||
UaaAuthenticationDetails details = null; | ||
UaaPrincipal princpal = null; | ||
List<? extends GrantedAuthority> authorities = EMPTY_LIST; | ||
Set<String> externalGroups = EMPTY_SET; | ||
long expiresAt = -1; | ||
long authenticatedTime = -1; | ||
boolean authenticated = false; | ||
Map<String,List<String>> userAttributes = EMPTY_MAP; | ||
while (jp.nextToken() != JsonToken.END_OBJECT) { | ||
if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { | ||
String fieldName = jp.getCurrentName(); | ||
jp.nextToken(); | ||
if (NULL_STRING.equals(jp.getText())) { | ||
//do nothing | ||
} else if (DETAILS.equals(fieldName)) { | ||
details = jp.readValueAs(UaaAuthenticationDetails.class); | ||
} else if (PRINCIPAL.equals(fieldName)) { | ||
princpal = jp.readValueAs(UaaPrincipal.class); | ||
} else if (AUTHORITIES.equals(fieldName)) { | ||
authorities = deserializeAuthorites(jp.readValueAs(new TypeReference<List<String>>(){})); | ||
} else if (EXTERNAL_GROUPS.equals(fieldName)) { | ||
externalGroups = jp.readValueAs(new TypeReference<Set<String>>(){}); | ||
} else if (EXPIRES_AT.equals(fieldName)) { | ||
expiresAt = jp.getLongValue(); | ||
} else if (AUTH_TIME.equals(fieldName)) { | ||
authenticatedTime = jp.getLongValue(); | ||
} else if (AUTHENTICATED.equals(fieldName)) { | ||
authenticated = jp.getBooleanValue(); | ||
} else if (USER_ATTRIBUTES.equals(fieldName)) { | ||
userAttributes = jp.readValueAs(new TypeReference<Map<String,List<String>>>() {}); | ||
} | ||
} | ||
} | ||
if (princpal==null) { | ||
throw new JsonMappingException("Missing "+UaaPrincipal.class.getName()); | ||
} | ||
return new UaaAuthentication(princpal, | ||
null, | ||
authorities, | ||
externalGroups, | ||
userAttributes, | ||
details, | ||
authenticated, | ||
authenticatedTime, | ||
expiresAt); | ||
} | ||
} |
Oops, something went wrong.