use of com.sun.identity.entitlement.JwtPrincipal in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldAllowJwtSubject.
@Test
public void shouldAllowJwtSubject() throws Exception {
// Given
final String subjectName = "test";
given(subjectContext.getCallerSubject()).willReturn(restSubject);
Jwt jwt = getJwtSubject(subjectName);
given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("jwt", jwt.build()))))));
// When
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then
Subject policySubject = request.getPolicySubject();
Set<JwtPrincipal> jwtPrincipals = policySubject.getPrincipals(JwtPrincipal.class);
assertThat(jwtPrincipals).hasSize(1);
assertThat(jwtPrincipals).contains(new JwtPrincipal(getJsonSubject(subjectName)));
}
use of com.sun.identity.entitlement.JwtPrincipal in project OpenAM by OpenRock.
the class PolicyRequestTest method shouldAllowJsonSubject.
@Test
public void shouldAllowJsonSubject() throws Exception {
// Given
final String subjectName = "test";
given(subjectContext.getCallerSubject()).willReturn(restSubject);
final JsonValue jwt = getJsonSubject(subjectName);
given(actionRequest.getContent()).willReturn(json(object(field("subject", object(field("claims", jwt.asMap()))))));
// When
Context context = buildContextStructure("/abc");
PolicyRequest request = getRequest(context, actionRequest);
// Then
Subject policySubject = request.getPolicySubject();
Set<JwtPrincipal> jwtPrincipals = policySubject.getPrincipals(JwtPrincipal.class);
assertThat(jwtPrincipals).hasSize(1);
assertThat(jwtPrincipals).contains(new JwtPrincipal(jwt));
}
use of com.sun.identity.entitlement.JwtPrincipal in project OpenAM by OpenRock.
the class UmaPolicyServiceImplDelegationTest method createSubject.
private Subject createSubject(String username) {
setupIdentityForUser(username, loggedInRealm);
AMIdentity identity = coreServicesWrapper.getIdentity(username, loggedInRealm);
JwtPrincipal principal = new JwtPrincipal(json(object(field("sub", identity.getUniversalId()))));
Set<Principal> principals = new HashSet<>();
principals.add(principal);
return new Subject(false, principals, Collections.emptySet(), Collections.emptySet());
}
use of com.sun.identity.entitlement.JwtPrincipal in project OpenAM by OpenRock.
the class ResourceSetService method createSubject.
protected Subject createSubject(String username, String realm) {
AMIdentity identity = coreWrapper.getIdentity(username, realm);
JwtPrincipal principal = new JwtPrincipal(json(object(field("sub", identity.getUniversalId()))));
Set<Principal> principals = new HashSet<>();
principals.add(principal);
return new Subject(false, principals, Collections.emptySet(), Collections.emptySet());
}
use of com.sun.identity.entitlement.JwtPrincipal in project OpenAM by OpenRock.
the class UmaUtils method createSubject.
/**
* Creates a {@code Subject} using the universal ID from the provided
* {@code AMIdentity}.
*
* @param identity The {@code AMIdentity}.
* @return A {@code Subject}.
*/
public static Subject createSubject(AMIdentity identity) {
JwtPrincipal principal = new JwtPrincipal(json(object(field("sub", identity.getUniversalId()))));
Set<Principal> principals = new HashSet<Principal>();
principals.add(principal);
return new Subject(false, principals, Collections.emptySet(), Collections.emptySet());
}
Aggregations