Skip to content

Commit

Permalink
Clean up and reenable tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Protsiuk <ivan.protsiuk@broadcom.com>
  • Loading branch information
duanemay committed May 30, 2024
1 parent 3e621a6 commit 6c5b09c
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 884 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.cloudfoundry.identity.uaa.util.JsonUtils;
import org.flywaydb.core.internal.util.StringUtils;
//import org.opensaml.saml2.metadata.provider.MetadataProviderException;
//import org.springframework.security.saml.context.SAMLContextProvider;
//import org.springframework.security.saml.context.SAMLMessageContext;

import javax.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.authentication;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.saml.context.SAMLMessageContext;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static java.util.Collections.EMPTY_MAP;

/**
Expand Down Expand Up @@ -60,15 +58,11 @@ public UaaAuthentication setLastLoginSuccessTime(Long lastLoginSuccessTime) {
return this;
}

//This is used when UAA acts as a SAML IdP
@JsonIgnore
// private transient SAMLMessageContext samlMessageContext;

/**
* Creates a token with the supplied array of authorities.
*
* @param authorities the collection of <tt>GrantedAuthority</tt>s for the
* principal represented by this authentication object.
* principal represented by this authentication object.
*/
public UaaAuthentication(UaaPrincipal principal,
Collection<? extends GrantedAuthority> authorities,
Expand Down Expand Up @@ -118,6 +112,16 @@ public UaaAuthentication(UaaPrincipal uaaPrincipal,
this.userAttributes = new HashMap<>(userAttributes);
}

public UaaAuthentication(UaaAuthentication existing, UaaPrincipal principal) {

this(principal, existing.getCredentials(), List.copyOf(existing.authorities), existing.getExternalGroups(),
existing.getUserAttributes(), existing.details, existing.isAuthenticated(),
existing.getAuthenticatedTime(), existing.getExpiresAt());
this.authContextClassRef = existing.authContextClassRef;
this.authenticationMethods = existing.authenticationMethods;
this.lastLoginSuccessTime = existing.lastLoginSuccessTime;
}

public long getAuthenticatedTime() {
return authenticatedTime;
}
Expand Down Expand Up @@ -199,12 +203,12 @@ public void setExternalGroups(Set<String> externalGroups) {
this.externalGroups = externalGroups;
}

public MultiValueMap<String,String> getUserAttributes() {
return new LinkedMultiValueMap<>(userAttributes!=null? userAttributes: EMPTY_MAP);
public MultiValueMap<String, String> getUserAttributes() {
return new LinkedMultiValueMap<>(userAttributes != null ? userAttributes : EMPTY_MAP);
}

public Map<String,List<String>> getUserAttributesAsMap() {
return userAttributes!=null ? new HashMap<>(userAttributes) : EMPTY_MAP;
public Map<String, List<String>> getUserAttributesAsMap() {
return userAttributes != null ? new HashMap<>(userAttributes) : EMPTY_MAP;
}

public void setUserAttributes(MultiValueMap<String, String> userAttributes) {
Expand All @@ -229,6 +233,7 @@ public Set<String> getAuthenticationMethods() {
}

public void setAuthenticationMethods(Set<String> authenticationMethods) {

this.authenticationMethods = authenticationMethods;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.saml2.Saml2Exception;
import org.springframework.security.web.firewall.RequestRejectedException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
Expand Down Expand Up @@ -129,13 +130,13 @@ public String error500(Model model, HttpServletRequest request, HttpServletRespo
logger.error("Internal error", genericException);

// check for common SAML related exceptions and redirect these to bad_request
// if (nonNull(genericException) &&
// (genericException.getCause() instanceof SAMLException || genericException.getCause() instanceof MetadataProviderException)) {
// Exception samlException = (Exception) genericException.getCause();
// model.addAttribute("saml_error", samlException.getMessage());
// response.setStatus(400);
// return EXTERNAL_AUTH_ERROR;
// }
if (nonNull(genericException) &&
(genericException.getCause() instanceof Saml2Exception)) {
Exception samlException = (Exception) genericException.getCause();
model.addAttribute("saml_error", samlException.getMessage());
response.setStatus(400);
return EXTERNAL_AUTH_ERROR;
}

populateBuildAndLinkInfo(model);
return ERROR;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.cloudfoundry.identity.uaa.provider.saml;

import org.cloudfoundry.identity.uaa.cache.UrlContentCache;
//import org.opensaml.saml2.metadata.provider.MetadataProviderException;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6c5b09c

Please sign in to comment.