Search in sources :

Example 1 with JwtPrincipal

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)));
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Jwt(org.forgerock.json.jose.jwt.Jwt) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 2 with JwtPrincipal

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));
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) JsonValue(org.forgerock.json.JsonValue) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 3 with JwtPrincipal

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());
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 4 with JwtPrincipal

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());
}
Also used : AMIdentity(com.sun.identity.idm.AMIdentity) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) Principal(java.security.Principal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Example 5 with JwtPrincipal

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());
}
Also used : JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) Principal(java.security.Principal) JwtPrincipal(com.sun.identity.entitlement.JwtPrincipal) Subject(javax.security.auth.Subject) HashSet(java.util.HashSet)

Aggregations

JwtPrincipal (com.sun.identity.entitlement.JwtPrincipal)5 Subject (javax.security.auth.Subject)5 Principal (java.security.Principal)3 HashSet (java.util.HashSet)3 AMIdentity (com.sun.identity.idm.AMIdentity)2 RealmContext (org.forgerock.openam.rest.RealmContext)2 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)2 ClientContext (org.forgerock.services.context.ClientContext)2 Context (org.forgerock.services.context.Context)2 Test (org.testng.annotations.Test)2 JsonValue (org.forgerock.json.JsonValue)1 SignedJwt (org.forgerock.json.jose.jws.SignedJwt)1 Jwt (org.forgerock.json.jose.jwt.Jwt)1