use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project geonetwork-microservices by geonetwork.
the class SearchControllerSecurityConfigurerTest method createToken.
private String createToken(String userName, List<GrantedAuthority> authorities) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userName, null, authorities);
OAuth2Request request = new OAuth2Request(null, "clientId", null, true, null, null, null, null, null);
OAuth2Authentication auth = new OAuth2Authentication(request, token);
return jwtAccessTokenConverter.enhance(new DefaultOAuth2AccessToken(""), auth).getValue();
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class CheckTokenEndpointTests method testClientWildcard.
@Test
public void testClientWildcard() throws Exception {
BaseClientDetails client = new BaseClientDetails("client", "zones", "zones.*.admin", "authorization_code, password", "scim.read, scim.write", "http://localhost:8080/uaa");
client.setAutoApproveScopes(Collections.singletonList("zones.*.admin"));
Map<String, BaseClientDetails> clientDetailsStore = Collections.singletonMap("client", client);
clientDetailsService.setClientDetailsStore(IdentityZoneHolder.get().getId(), clientDetailsStore);
tokenServices.setClientDetailsService(clientDetailsService);
authorizationRequest = new AuthorizationRequest("client", Collections.singleton("zones.myzone.admin"));
authorizationRequest.setResourceIds(new HashSet<>(Arrays.asList("client", "zones")));
authentication = new OAuth2Authentication(authorizationRequest.createOAuth2Request(), UaaAuthenticationTestFactory.getAuthentication(userId, userName, "olds@vmware.com"));
endpoint.checkToken(tokenServices.createAccessToken(authentication).getValue(), Collections.emptyList(), request);
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class LocalUaaRestTemplateTests method acquireAccessToken.
@Test
void acquireAccessToken() {
OAuth2ClientContext mockOAuth2ClientContext = mock(OAuth2ClientContext.class);
OAuth2AccessToken mockOAuth2AccessToken = mock(OAuth2AccessToken.class);
when(mockAuthorizationServerTokenServices.createAccessToken(any())).thenReturn(mockOAuth2AccessToken);
OAuth2AccessToken actualResult = localUaaRestTemplate.acquireAccessToken(mockOAuth2ClientContext);
assertThat(actualResult, is(mockOAuth2AccessToken));
ImmutableMap<String, String> requestParameters = ImmutableMap.<String, String>builder().put(OAuth2Utils.CLIENT_ID, "login").put(OAuth2Utils.GRANT_TYPE, GRANT_TYPE_CLIENT_CREDENTIALS).build();
OAuth2Request request = new OAuth2Request(requestParameters, "login", new HashSet<>(), true, Sets.newHashSet("something", "else"), Sets.newHashSet(OriginKeys.UAA), null, new HashSet<>(), ImmutableMap.<String, Serializable>builder().build());
OAuth2Authentication authentication = new OAuth2Authentication(request, null);
verify(mockIdentityZoneManager).getCurrentIdentityZoneId();
verify(mockMultitenantClientServices).loadClientByClientId("login", "currentIdentityZoneId");
verify(mockOAuth2ClientContext).setAccessToken(mockOAuth2AccessToken);
verify(mockAuthorizationServerTokenServices).createAccessToken(authentication);
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class AbstractUaaEvent method getOrigin.
// Ideally we want to get to the point where details is never null, but this
// isn't currently possible
// due to some OAuth authentication scenarios which don't set it.
protected String getOrigin(Principal principal) {
if (principal instanceof Authentication) {
Authentication caller = (Authentication) principal;
StringBuilder builder = new StringBuilder();
if (caller instanceof OAuth2Authentication) {
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) caller;
builder.append("client=").append(oAuth2Authentication.getOAuth2Request().getClientId());
if (!oAuth2Authentication.isClientOnly()) {
builder.append(", ").append("user=").append(oAuth2Authentication.getName());
}
} else {
builder.append("caller=").append(caller.getName());
}
if (caller.getDetails() != null) {
builder.append(", details=(");
try {
@SuppressWarnings("unchecked") Map<String, Object> map = JsonUtils.readValue((String) caller.getDetails(), new TypeReference<Map<String, Object>>() {
});
if (map.containsKey("remoteAddress")) {
builder.append("remoteAddress=").append(map.get("remoteAddress")).append(", ");
}
builder.append("type=").append(caller.getDetails().getClass().getSimpleName());
} catch (Exception e) {
// ignore
builder.append(caller.getDetails());
}
appendTokenDetails(caller, builder);
builder.append(")");
}
return builder.toString();
}
return principal == null ? null : principal.getName();
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class LoginServerTokenEndpointFilter method onSuccessfulAuthentication.
@Override
protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
super.onSuccessfulAuthentication(request, response, authResult);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if (auth instanceof OAuth2Authentication) {
((OAuth2Authentication) auth).setAuthenticated(true);
}
}
Aggregations