Skip to content

Commit

Permalink
Merge branch 'feature/better_print' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed Jan 9, 2018
1 parent d27f9ed commit a61bfab
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*******************************************************************************/
package org.cloudfoundry.identity.uaa.authentication;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.bouncycastle.util.encoders.Base64;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
* Contains additional information about the authentication request which may be
* of use in auditing etc.
Expand Down Expand Up @@ -113,12 +113,6 @@ public String toString() {
}
sb.append("clientId=").append(clientId);
}
if (sessionId != null) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append("sessionId=").append(sessionId);
}
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* ****************************************************************************
* Cloud Foundry
* Copyright (c) [2009-2018] 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.event;

import org.cloudfoundry.identity.uaa.authentication.UaaAuthenticationDetails;
import org.cloudfoundry.identity.uaa.user.UaaUser;

import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.security.core.Authentication;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;

public class UserAuthenticationSuccessEventTests {

@Test
public void get_origin_from_request() throws Exception {
MockHttpSession session = new MockHttpSession(null, "the-id");
MockHttpServletRequest request = new MockHttpServletRequest("GET","/oauth/authorize");
request.setSession(session);
request.setRemoteAddr("127.10.10.10");
UaaAuthenticationDetails details = new UaaAuthenticationDetails(request, "client-id");

UserAuthenticationSuccessEvent event = new UserAuthenticationSuccessEvent(mock(UaaUser.class), mock(Authentication.class));
String origin = event.getOrigin(details);

assertThat(origin, containsString("remoteAddress=127.10.10.10"));
assertThat(origin, containsString("clientId=client-id"));
assertThat(origin, not(containsString("sessionId=")));
}
}

0 comments on commit a61bfab

Please sign in to comment.