use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class OA4MPServletInitializer method init.
@Override
public void init() throws ServletException {
if (isInitRun)
return;
isInitRun = true;
MyProxyDelegationServlet mps = (MyProxyDelegationServlet) getServlet();
try {
// mps.storeUpdates();
mps.processStoreCheck(mps.getTransactionStore());
mps.processStoreCheck(mps.getServiceEnvironment().getClientStore());
mps.processStoreCheck(mps.getServiceEnvironment().getClientApprovalStore());
} catch (IOException | SQLException e) {
e.printStackTrace();
throw new ServletException("Could not update table", e);
}
Cleanup transactionCleanup = MyProxyDelegationServlet.transactionCleanup;
ServiceEnvironmentImpl env = (ServiceEnvironmentImpl) getEnvironment();
MyLoggingFacade logger = env.getMyLogger();
logger.info("Cleaning up incomplete client registrations");
if (transactionCleanup == null) {
transactionCleanup = new Cleanup<>(logger);
// set it in the servlet
MyProxyDelegationServlet.transactionCleanup = transactionCleanup;
transactionCleanup.setStopThread(false);
transactionCleanup.setMap(env.getTransactionStore());
transactionCleanup.addRetentionPolicy(new ValidTimestampPolicy());
transactionCleanup.start();
logger.info("Starting transaction store cleanup thread");
}
Cleanup<Identifier, CachedObject> myproxyConnectionCleanup = MyProxyDelegationServlet.myproxyConnectionCleanup;
if (myproxyConnectionCleanup == null) {
myproxyConnectionCleanup = new Cleanup<Identifier, CachedObject>(logger) {
@Override
public List<CachedObject> age() {
List<CachedObject> x = super.age();
// is just trying to clean up afterwards.
for (CachedObject co : x) {
Object mp = co.getValue();
if (mp instanceof MyProxyConnectable) {
try {
((MyProxyConnectable) mp).close();
} catch (Throwable t) {
// don't care if it fails, get rid of it.
}
}
}
return x;
}
};
// set it in the servlet
MyProxyDelegationServlet.myproxyConnectionCleanup = myproxyConnectionCleanup;
myproxyConnectionCleanup.setStopThread(false);
Cache myproxyConnectionCache = MyProxyDelegationServlet.myproxyConnectionCache;
if (myproxyConnectionCache == null) {
myproxyConnectionCache = new Cache();
// set it in the servlet
MyProxyDelegationServlet.myproxyConnectionCache = myproxyConnectionCache;
}
myproxyConnectionCleanup.setMap(myproxyConnectionCache);
myproxyConnectionCleanup.addRetentionPolicy(new ConnectionCacheRetentionPolicy(myproxyConnectionCache, env.getTransactionStore()));
myproxyConnectionCleanup.start();
logger.info("Starting myproxy connection cache cleanup thread");
}
AbstractCLIApprover.ClientApprovalThread caThread = MyProxyDelegationServlet.caThread;
if (caThread != null && !caThread.isAlive()) {
caThread.setStopThread(false);
caThread.start();
}
KeyPairPopulationThread kpt = MyProxyDelegationServlet.kpt;
if (kpt != null && !kpt.isAlive()) {
kpt.setStopThread(false);
kpt.start();
}
try {
setupNotifiers();
} catch (IOException e) {
throw new GeneralException("Error: could not set up notifiers ", e);
}
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class RequestFactory method convertToRequest.
public static AbstractDDRequest convertToRequest(JSONObject json) {
AbstractDDRequest req = null;
BaseClient client = SATFactory.getSubject(json);
Action action = SATFactory.getMethod(json);
if (action instanceof MissingAction) {
throw new GeneralException("Error: no valid method found");
}
Type type = SATFactory.getType(json);
BaseClient target = SATFactory.getTarget(json);
switch(SATFactory.getSubjectValue(json)) {
case SUBJECT_ADMIN_VALUE:
// return createSubjectAdminRequest(json);
case SUBJECT_CLIENT_VALUE:
break;
case SUBJECT_UNKNOWN_VALUE:
default:
throw new GeneralException("Unknown subject type");
}
return req;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class RequestFactory method createRequest.
/* ***** Attribute requests */
public static AttributeGetRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionGet actionGet, OA2Client cTarget, JSON content) {
// JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeGetRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class RequestFactory method createRequest.
public static AttributeRemoveRequest createRequest(AdminClient aSubj, TypeAttribute typeAttribute, ActionRemove actionRemove, OA2Client cTarget, JSON content) {
// JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeRemoveRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class ClientServer method create.
public CreateResponse create(CreateRequest request) {
if (request.getAdminClient() != null && (request.getAdminClient().getIdentifier() == null || request.getAdminClient().getIdentifierString().length() == 0)) {
throw new GeneralException("Error: An admin client was specified, but no identifier for this client was given. Request rejected.");
}
// canCreate(request);
// requires and admin client and hashmap
ColumnMap values = new ColumnMap();
values.putAll(request.getAttributes());
// values.putAll(); // add all the values passed in
ClientKeys keys = (ClientKeys) getClientStore().getACConverter().getKeys();
OA2Client client = (OA2Client) getClientStore().create();
values.put(keys.identifier(), client.getIdentifier());
values.put(keys.creationTS(), client.getCreationTS());
String secret = null;
if (values.containsKey(keys.secret())) {
// if the secret is supplied, just store its hash
secret = (String) values.get(keys.secret());
} else {
// no secret means to create one.
byte[] bytes = new byte[cose.getClientSecretLength()];
random.nextBytes(bytes);
secret = Base64.encodeBase64URLSafeString(bytes);
}
String hash = DigestUtils.sha1Hex(secret);
values.put(keys.secret(), hash);
getClientStore().getACConverter().fromMap(values, client);
getClientStore().save(client);
// set the permissions for this.
if (request.getAdminClient() != null) {
// if there is no admin client, then do not set permissions for it. It is possible for a client to simply
// be created and manage itself.
PermissionServer permissionServer = new PermissionServer(cose);
permissionServer.process(RequestFactory.createRequest(request.getAdminClient(), new TypePermission(), new ActionAdd(), client, null));
}
// CIL-414 Make sure an approval record is created here so we can accurately track how many approvals are pending
ClientApproval approval = (ClientApproval) getClientApprovalStore().create();
approval.setApproved(false);
approval.setIdentifier(client.getIdentifier());
getClientApprovalStore().save(approval);
return new CreateResponse(client, secret);
}
Aggregations