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");
}
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");
}
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");
}
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");
}
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";
}
Aggregations