use of com.runwaysdk.business.rbac.Authenticate in project geoprism-registry by terraframe.
the class GeoRegistryUtil method createHierarchyType.
@Authenticate
public static String createHierarchyType(String htJSON) {
RegistryAdapter adapter = ServiceFactory.getAdapter();
HierarchyType hierarchyType = HierarchyType.fromJSON(htJSON, adapter);
ServiceFactory.getHierarchyPermissionService().enforceCanCreate(hierarchyType.getOrganizationCode());
ServerHierarchyType sType = new ServerHierarchyTypeBuilder().createHierarchyType(hierarchyType);
// The transaction did not error out, so it is safe to put into the cache.
ServiceFactory.getMetadataCache().addHierarchyType(sType);
return hierarchyType.getCode();
}
use of com.runwaysdk.business.rbac.Authenticate in project geoprism-registry by terraframe.
the class GeoRegistryUtil method applyClassificationType.
@Authenticate
public static String applyClassificationType(String json) {
JsonObject object = JsonParser.parseString(json).getAsJsonObject();
ClassificationType type = ClassificationType.apply(object);
return type.toJSON().toString();
}
use of com.runwaysdk.business.rbac.Authenticate in project geoprism-registry by terraframe.
the class RegistrySessionService method ologin.
/**
* Serves as a "redirect url" for logging into DHIS2 via oauth.
*
* @param serverId
* @param code
* @param locales
* @param redirectBase
* @return
*/
@Authenticate
public static java.lang.String ologin(java.lang.String serverId, java.lang.String code, java.lang.String locales, java.lang.String redirectBase) {
try {
// We used to try to build this from the controller but it would include stuff (like the port :443) which then wouldn't match
// with the redirect url the client specified in DHIS2. Therefore this has to be something that the user can set (or, at least,
// in a properties file)
redirectBase = GeoregistryProperties.getRemoteServerUrl();
String redirect = redirectBase + "cgrsession/ologin";
OauthServer server = OauthServer.get(serverId);
/*
* Get the access token
*/
TokenRequestBuilder tokenBuilder = OAuthClientRequest.tokenLocation(server.getTokenLocation());
tokenBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
tokenBuilder.setRedirectURI(redirect);
tokenBuilder.setCode(code);
String auth = server.getClientId() + ":" + server.getSecretKey();
OAuthClientRequest tokenRequest = tokenBuilder.buildBodyMessage();
tokenRequest.setHeader("Accept", "application/json");
tokenRequest.setHeader("Authorization", "Basic " + new String(Base64.getEncoder().encode(auth.getBytes())));
URLConnectionClient connClient = new URLConnectionClient();
OAuthClient oAuthClient = new OAuthClient(connClient);
OAuthJSONAccessTokenResponse accessToken = oAuthClient.accessToken(tokenRequest, OAuth.HttpMethod.POST, OAuthJSONAccessTokenResponse.class);
/*
* Request the user information
*/
OAuthBearerClientRequest requestBuilder = new OAuthBearerClientRequest(server.getProfileLocation());
requestBuilder.setAccessToken(accessToken.getAccessToken());
OAuthClientRequest bearerRequest = requestBuilder.buildQueryMessage();
OAuthResourceResponse resourceResponse = oAuthClient.resource(bearerRequest, OAuth.HttpMethod.GET, OAuthResourceResponse.class);
String body = resourceResponse.getBody();
JSONObject object = new JSONObject(body);
final String username = object.getJSONObject("userCredentials").getString("username");
SingleActorDAOIF profile = RegistrySessionService.getActor(server, username);
String sessionId = SessionFacade.logIn(profile, LocaleSerializer.deserialize(locales));
JsonObject json = new JsonObject();
json.addProperty("sessionId", sessionId);
json.addProperty("username", username);
return json.toString();
} catch (JSONException | OAuthSystemException | OAuthProblemException e) {
throw new InvalidLoginException(e);
}
}
use of com.runwaysdk.business.rbac.Authenticate in project geoprism-registry by terraframe.
the class GeoRegistryUtil method importTypes.
@Authenticate
public static void importTypes(String orgCode, InputStream istream) {
Organization organization = Organization.getByCode(orgCode);
XMLImporter xmlImporter = new XMLImporter();
xmlImporter.importXMLDefinitions(organization, istream);
}
Aggregations