Search in sources :

Example 1 with SystemScope

use of org.mitre.oauth2.model.SystemScope in project OpenID-Connect-Java-Spring-Server by mitreid-connect.

the class MITREidDataService_1_3 method readSystemScopes.

/**
 * Read the list of system scopes from the reader and insert them into the
 * scope repository.
 *
 * @param reader
 * @throws IOException
 */
private void readSystemScopes(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        SystemScope scope = new SystemScope();
        reader.beginObject();
        while (reader.hasNext()) {
            switch(reader.peek()) {
                case END_OBJECT:
                    continue;
                case NAME:
                    String name = reader.nextName();
                    if (reader.peek() == JsonToken.NULL) {
                        reader.skipValue();
                    } else if (name.equals(VALUE)) {
                        scope.setValue(reader.nextString());
                    } else if (name.equals(DESCRIPTION)) {
                        scope.setDescription(reader.nextString());
                    } else if (name.equals(RESTRICTED)) {
                        scope.setRestricted(reader.nextBoolean());
                    } else if (name.equals(DEFAULT_SCOPE)) {
                        scope.setDefaultScope(reader.nextBoolean());
                    } else if (name.equals(ICON)) {
                        scope.setIcon(reader.nextString());
                    } else {
                        logger.debug("found unexpected entry");
                        reader.skipValue();
                    }
                    break;
                default:
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                    continue;
            }
        }
        reader.endObject();
        sysScopeRepository.save(scope);
    }
    reader.endArray();
    logger.info("Done reading system scopes");
}
Also used : SystemScope(org.mitre.oauth2.model.SystemScope)

Example 2 with SystemScope

use of org.mitre.oauth2.model.SystemScope in project OpenID-Connect-Java-Spring-Server by mitreid-connect.

the class MITREidDataService_1_3 method writeSystemScopes.

/**
 * @param writer
 */
private void writeSystemScopes(JsonWriter writer) {
    for (SystemScope sysScope : sysScopeRepository.getAll()) {
        try {
            writer.beginObject();
            writer.name(ID).value(sysScope.getId());
            writer.name(DESCRIPTION).value(sysScope.getDescription());
            writer.name(ICON).value(sysScope.getIcon());
            writer.name(VALUE).value(sysScope.getValue());
            writer.name(RESTRICTED).value(sysScope.isRestricted());
            writer.name(DEFAULT_SCOPE).value(sysScope.isDefaultScope());
            writer.endObject();
            logger.debug("Wrote system scope {}", sysScope.getId());
        } catch (IOException ex) {
            logger.error("Unable to write system scope {}", sysScope.getId(), ex);
        }
    }
    logger.info("Done writing system scopes");
}
Also used : IOException(java.io.IOException) SystemScope(org.mitre.oauth2.model.SystemScope)

Example 3 with SystemScope

use of org.mitre.oauth2.model.SystemScope in project OpenID-Connect-Java-Spring-Server by mitreid-connect.

the class MITREidDataService_1_1 method readSystemScopes.

/**
 * Read the list of system scopes from the reader and insert them into the
 * scope repository.
 *
 * @param reader
 * @throws IOException
 */
private void readSystemScopes(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        SystemScope scope = new SystemScope();
        reader.beginObject();
        while (reader.hasNext()) {
            switch(reader.peek()) {
                case END_OBJECT:
                    continue;
                case NAME:
                    String name = reader.nextName();
                    if (reader.peek() == JsonToken.NULL) {
                        reader.skipValue();
                    } else if (name.equals("value")) {
                        scope.setValue(reader.nextString());
                    } else if (name.equals("description")) {
                        scope.setDescription(reader.nextString());
                    } else if (name.equals("allowDynReg")) {
                        // previously "allowDynReg" scopes are now tagged as "not restricted" and vice versa
                        scope.setRestricted(!reader.nextBoolean());
                    } else if (name.equals("defaultScope")) {
                        scope.setDefaultScope(reader.nextBoolean());
                    } else if (name.equals("structured")) {
                        logger.warn("Found a structured scope, ignoring structure");
                    } else if (name.equals("structuredParameter")) {
                        logger.warn("Found a structured scope, ignoring structure");
                    } else if (name.equals("icon")) {
                        scope.setIcon(reader.nextString());
                    } else {
                        logger.debug("found unexpected entry");
                        reader.skipValue();
                    }
                    break;
                default:
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                    continue;
            }
        }
        reader.endObject();
        sysScopeRepository.save(scope);
    }
    reader.endArray();
    logger.info("Done reading system scopes");
}
Also used : SystemScope(org.mitre.oauth2.model.SystemScope)

Example 4 with SystemScope

use of org.mitre.oauth2.model.SystemScope in project OpenID-Connect-Java-Spring-Server by mitreid-connect.

the class MITREidDataService_1_2 method readSystemScopes.

/**
 * Read the list of system scopes from the reader and insert them into the
 * scope repository.
 *
 * @param reader
 * @throws IOException
 */
private void readSystemScopes(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        SystemScope scope = new SystemScope();
        reader.beginObject();
        while (reader.hasNext()) {
            switch(reader.peek()) {
                case END_OBJECT:
                    continue;
                case NAME:
                    String name = reader.nextName();
                    if (reader.peek() == JsonToken.NULL) {
                        reader.skipValue();
                    } else if (name.equals(VALUE)) {
                        scope.setValue(reader.nextString());
                    } else if (name.equals(DESCRIPTION)) {
                        scope.setDescription(reader.nextString());
                    } else if (name.equals(RESTRICTED)) {
                        scope.setRestricted(reader.nextBoolean());
                    } else if (name.equals(DEFAULT_SCOPE)) {
                        scope.setDefaultScope(reader.nextBoolean());
                    } else if (name.equals(ICON)) {
                        scope.setIcon(reader.nextString());
                    } else if (name.equals(STRUCTURED)) {
                        logger.warn("Found a structured scope, ignoring structure");
                    } else if (name.equals(STRUCTURED_PARAMETER)) {
                        logger.warn("Found a structured scope, ignoring structure");
                    } else {
                        logger.debug("found unexpected entry");
                        reader.skipValue();
                    }
                    break;
                default:
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                    continue;
            }
        }
        reader.endObject();
        sysScopeRepository.save(scope);
    }
    reader.endArray();
    logger.info("Done reading system scopes");
}
Also used : SystemScope(org.mitre.oauth2.model.SystemScope)

Example 5 with SystemScope

use of org.mitre.oauth2.model.SystemScope in project OpenID-Connect-Java-Spring-Server by mitreid-connect.

the class DeviceEndpoint method readUserCode.

@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping(value = "/" + USER_URL + "/verify", method = RequestMethod.POST)
public String readUserCode(@RequestParam("user_code") String userCode, ModelMap model, HttpSession session) {
    // look up the request based on the user code
    DeviceCode dc = deviceCodeService.lookUpByUserCode(userCode);
    // we couldn't find the device code
    if (dc == null) {
        model.addAttribute("error", "noUserCode");
        return "requestUserCode";
    }
    // make sure the code hasn't expired yet
    if (dc.getExpiration() != null && dc.getExpiration().before(new Date())) {
        model.addAttribute("error", "expiredUserCode");
        return "requestUserCode";
    }
    // make sure the device code hasn't already been approved
    if (dc.isApproved()) {
        model.addAttribute("error", "userCodeAlreadyApproved");
        return "requestUserCode";
    }
    ClientDetailsEntity client = clientService.loadClientByClientId(dc.getClientId());
    model.put("client", client);
    model.put("dc", dc);
    // pre-process the scopes
    Set<SystemScope> scopes = scopeService.fromStrings(dc.getScope());
    Set<SystemScope> sortedScopes = new LinkedHashSet<>(scopes.size());
    Set<SystemScope> systemScopes = scopeService.getAll();
    // sort scopes for display based on the inherent order of system scopes
    for (SystemScope s : systemScopes) {
        if (scopes.contains(s)) {
            sortedScopes.add(s);
        }
    }
    // add in any scopes that aren't system scopes to the end of the list
    sortedScopes.addAll(Sets.difference(scopes, systemScopes));
    model.put("scopes", sortedScopes);
    AuthorizationRequest authorizationRequest = oAuth2RequestFactory.createAuthorizationRequest(dc.getRequestParameters());
    session.setAttribute("authorizationRequest", authorizationRequest);
    session.setAttribute("deviceCode", dc);
    return "approveDevice";
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClientDetailsEntity(org.mitre.oauth2.model.ClientDetailsEntity) AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) DeviceCode(org.mitre.oauth2.model.DeviceCode) SystemScope(org.mitre.oauth2.model.SystemScope) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SystemScope (org.mitre.oauth2.model.SystemScope)30 ClientDetailsEntity (org.mitre.oauth2.model.ClientDetailsEntity)14 Test (org.junit.Test)12 AuthenticationHolderEntity (org.mitre.oauth2.model.AuthenticationHolderEntity)11 OAuth2AccessTokenEntity (org.mitre.oauth2.model.OAuth2AccessTokenEntity)11 OAuth2RefreshTokenEntity (org.mitre.oauth2.model.OAuth2RefreshTokenEntity)11 JsonObject (com.google.gson.JsonObject)10 HashSet (java.util.HashSet)10 JsonElement (com.google.gson.JsonElement)9 ApprovedSite (org.mitre.openid.connect.model.ApprovedSite)9 JsonArray (com.google.gson.JsonArray)8 JsonParser (com.google.gson.JsonParser)8 JsonWriter (com.google.gson.stream.JsonWriter)8 StringWriter (java.io.StringWriter)8 Date (java.util.Date)8 BlacklistedSite (org.mitre.openid.connect.model.BlacklistedSite)8 WhitelistedSite (org.mitre.openid.connect.model.WhitelistedSite)8 Matchers.anyString (org.mockito.Matchers.anyString)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6