Search in sources :

Example 1 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.

the class RegisterPermissionWSTest method testRegisterPermission.

@Test(dependsOnMethods = { "init" })
public void testRegisterPermission() throws Exception {
    final UmaPermission r = new UmaPermission();
    r.setResourceId(resource.getId());
    r.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view"));
    final PermissionTicket ticket = TUma.registerPermission(url, pat, r, umaPermissionPath);
    UmaTestUtil.assert_(ticket);
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 2 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.

the class UmaRegisterPermissionFlowHttpTest method registerResourcePermission.

public String registerResourcePermission(String resourceId, List<String> scopes) throws Exception {
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(resourceId);
    permission.setScopes(scopes);
    PermissionTicket ticket = getPermissionService().registerPermission("Bearer " + this.registerResourceTest.pat.getAccessToken(), UmaPermissionList.instance(permission));
    UmaTestUtil.assert_(ticket);
    this.ticket = ticket.getTicket();
    return ticket.getTicket();
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission)

Example 3 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxAuth by GluuFederation.

the class AccessProtectedResourceFlowWSTest method _4_registerPermissionForRpt.

/*
	 * **************************************************************** 4.
	 * Registers permission for RPT
	 */
@Test(dependsOnMethods = { "_3_hostDeterminesRptStatus" })
@Parameters({ "umaPermissionPath" })
public void _4_registerPermissionForRpt(String umaPermissionPath) throws Exception {
    final UmaPermission r = new UmaPermission();
    r.setResourceId(resource.getId());
    r.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view"));
    ticket = TUma.registerPermission(url, pat, r, umaPermissionPath);
    UmaTestUtil.assert_(ticket);
}
Also used : UmaPermission(org.gluu.oxauth.model.uma.UmaPermission) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 4 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxTrust by GluuFederation.

the class UmaPermissionService method validateRptToken.

public Pair<Boolean, Response> validateRptToken(Token patToken, String authorization, String resourceId, List<String> scopeIds) {
    /*
		 * //caller of this method never pass null patToken if (patToken == null) {
		 * return authenticationFailure; }
		 */
    log.trace("Validating RPT, resourceId: {}, scopeIds: {}, authorization: {}", resourceId, scopeIds, authorization);
    if (StringHelper.isNotEmpty(authorization) && authorization.startsWith("Bearer ")) {
        String rptToken = authorization.substring(7);
        RptIntrospectionResponse rptStatusResponse = getStatusResponse(patToken, rptToken);
        log.trace("RPT status response: {} ", rptStatusResponse);
        if ((rptStatusResponse == null) || !rptStatusResponse.getActive()) {
            log.warn("Status response for RPT token: '{}' is invalid, will do a retry", rptToken);
        } else {
            boolean rptHasPermissions = isRptHasPermissions(rptStatusResponse);
            if (rptHasPermissions) {
                // Collect all scopes
                List<String> returnScopeIds = new LinkedList<String>();
                for (UmaPermission umaPermission : rptStatusResponse.getPermissions()) {
                    if (umaPermission.getScopes() != null) {
                        returnScopeIds.addAll(umaPermission.getScopes());
                    }
                }
                if (returnScopeIds.containsAll(scopeIds)) {
                    return authenticationSuccess;
                }
                log.error("Status response for RPT token: '{}' not contains right permissions", rptToken);
            }
        }
    }
    Response registerPermissionsResponse = prepareRegisterPermissionsResponse(patToken, resourceId, scopeIds);
    if (registerPermissionsResponse == null) {
        return authenticationFailure;
    }
    return new Pair<Boolean, Response>(true, registerPermissionsResponse);
}
Also used : RptIntrospectionResponse(org.gluu.oxauth.model.uma.RptIntrospectionResponse) Response(javax.ws.rs.core.Response) HttpResponse(org.apache.http.HttpResponse) RptIntrospectionResponse(org.gluu.oxauth.model.uma.RptIntrospectionResponse) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission) LinkedList(java.util.LinkedList) Pair(org.gluu.util.Pair)

Example 5 with UmaPermission

use of org.gluu.oxauth.model.uma.UmaPermission in project oxTrust by GluuFederation.

the class UmaPermissionService method registerResourcePermission.

public String registerResourcePermission(Token patToken, String resourceId, List<String> scopes) {
    // TODO: Added this if as a hack since init method is not called upon app startup in scim project
    if (permissionService == null) {
        init(null);
    }
    // end
    UmaPermission permission = new UmaPermission();
    permission.setResourceId(resourceId);
    permission.setScopes(scopes);
    PermissionTicket ticket = permissionService.registerPermission("Bearer " + patToken.getAccessToken(), UmaPermissionList.instance(permission));
    if (ticket == null) {
        return null;
    }
    return ticket.getTicket();
}
Also used : PermissionTicket(org.gluu.oxauth.model.uma.PermissionTicket) UmaPermission(org.gluu.oxauth.model.uma.UmaPermission)

Aggregations

UmaPermission (org.gluu.oxauth.model.uma.UmaPermission)7 PermissionTicket (org.gluu.oxauth.model.uma.PermissionTicket)5 BaseTest (org.gluu.oxauth.BaseTest)4 Test (org.testng.annotations.Test)4 Response (javax.ws.rs.core.Response)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 Builder (javax.ws.rs.client.Invocation.Builder)1 HttpResponse (org.apache.http.HttpResponse)1 RptIntrospectionResponse (org.gluu.oxauth.model.uma.RptIntrospectionResponse)1 UmaResourceResponse (org.gluu.oxauth.model.uma.UmaResourceResponse)1 Pair (org.gluu.util.Pair)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1 Parameters (org.testng.annotations.Parameters)1