use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class LoginAuthenticationManagerTests method setUp.
@BeforeEach
void setUp() {
publisher = TestApplicationEventPublisher.forEventClass(IdentityProviderAuthenticationSuccessEvent.class);
mockIdentityZoneManager = mock(IdentityZoneManager.class);
manager = new LoginAuthenticationManager(mockIdentityZoneManager);
manager.setApplicationEventPublisher(publisher);
userDatabase = mock(UaaUserDatabase.class);
manager.setUserDatabase(userDatabase);
OAuth2Authentication oauth2Authentication = new OAuth2Authentication(new AuthorizationRequest("client", Arrays.asList("read", "write")).createOAuth2Request(), null);
SecurityContextImpl context = new SecurityContextImpl();
context.setAuthentication(oauth2Authentication);
SecurityContextHolder.setContext(context);
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class PasswordChangeEventPublisherTests method setUp.
@BeforeEach
void setUp() {
mockScimUserProvisioning = mock(ScimUserProvisioning.class);
mockApplicationEventPublisher = mock(ApplicationEventPublisher.class);
mockIdentityZoneManager = mock(IdentityZoneManager.class);
currentZoneId = "currentZoneId-" + RandomStringUtils.random(8);
subject = new PasswordChangeEventPublisher(mockScimUserProvisioning, mockIdentityZoneManager);
subject.setApplicationEventPublisher(mockApplicationEventPublisher);
authentication = new OAuth2Authentication(new AuthorizationRequest("client", Collections.singletonList("read")).createOAuth2Request(), UaaPasswordTestFactory.getAuthentication("ID", "joe", "joe@test.org"));
SecurityContextHolder.getContext().setAuthentication(authentication);
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class DefaultSecurityContextAccessor method getAuthenticationInfo.
@Override
public String getAuthenticationInfo() {
Authentication a = SecurityContextHolder.getContext().getAuthentication();
if (a instanceof OAuth2Authentication) {
OAuth2Authentication oauth = ((OAuth2Authentication) a);
String info = getClientId();
if (!oauth.isClientOnly()) {
info = info + "; " + a.getName() + "; " + getUserId();
}
return info;
} else {
return a.getName();
}
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class DefaultSecurityContextAccessor method isAdmin.
@Override
public boolean isAdmin() {
Authentication a = SecurityContextHolder.getContext().getAuthentication();
String[] adminRoles = new String[] { "uaa.admin" };
if (a == null) {
return false;
}
boolean result = false;
if (a instanceof OAuth2Authentication) {
OAuth2Authentication oa = (OAuth2Authentication) a;
result = OAuth2ExpressionUtils.hasAnyScope(oa, adminRoles);
} else {
result = hasAnyAdminScope(a, adminRoles);
}
String zoneAdminRole = "zones." + IdentityZoneHolder.get().getId() + ".admin";
if (!result) {
ContextSensitiveOAuth2SecurityExpressionMethods eval = new ContextSensitiveOAuth2SecurityExpressionMethods(a, IdentityZone.getUaa());
result = eval.hasScopeInAuthZone(zoneAdminRole);
}
return result;
}
use of org.maxkey.authz.oauth2.provider.OAuth2Authentication in project uaa by cloudfoundry.
the class DefaultSecurityContextAccessorTests method zoneAdminUserIsNotAdmin_BecauseOriginIsNotUaa.
@Test
void zoneAdminUserIsNotAdmin_BecauseOriginIsNotUaa() {
BaseClientDetails client = new BaseClientDetails();
List<SimpleGrantedAuthority> authorities = new LinkedList<>();
authorities.add(new SimpleGrantedAuthority("zones." + IdentityZoneHolder.get().getId() + ".admin"));
client.setAuthorities(authorities);
UaaPrincipal principal = new UaaPrincipal("id", "username", "email", OriginKeys.UAA, null, MultitenancyFixture.identityZone("test", "test").getId());
UaaAuthentication userAuthentication = new UaaAuthentication(principal, authorities, new UaaAuthenticationDetails(new MockHttpServletRequest()));
AuthorizationRequest authorizationRequest = new AuthorizationRequest("admin", UaaStringUtils.getStringsFromAuthorities(authorities));
authorizationRequest.setResourceIdsAndAuthoritiesFromClientDetails(client);
SecurityContextHolder.getContext().setAuthentication(new OAuth2Authentication(authorizationRequest.createOAuth2Request(), userAuthentication));
assertFalse(defaultSecurityContextAccessor.isAdmin());
}
Aggregations