use of won.protocol.exception.WonProtocolException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method register.
@RequestMapping(value = "${uri.path.resource}", method = RequestMethod.POST, produces = { "text/plain" })
public ResponseEntity<String> register(@RequestParam("register") String registeredType, HttpServletRequest request) throws CertificateException, UnsupportedEncodingException {
logger.debug("REGISTERING " + registeredType);
PreAuthenticatedAuthenticationToken authentication = (PreAuthenticatedAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
if (!(authentication instanceof PreAuthenticatedAuthenticationToken)) {
throw new BadCredentialsException("Could not register: PreAuthenticatedAuthenticationToken expected");
}
// Object principal = authentication.getPrincipal();
Object credentials = authentication.getCredentials();
X509Certificate cert;
if (credentials instanceof X509Certificate) {
cert = (X509Certificate) credentials;
} else {
throw new BadCredentialsException("Could not register: expected to find a X509Certificate in the request");
}
try {
if ("owner".equals(registeredType)) {
String result = registrationServer.registerOwner(cert);
logger.debug("successfully registered owner");
return new ResponseEntity<>(result, HttpStatus.OK);
}
if ("node".equals(registeredType)) {
String result = registrationServer.registerNode(cert);
logger.debug("successfully registered node");
return new ResponseEntity<>(result, HttpStatus.OK);
} else {
String supportedTypesMsg = "Request parameter error; supported 'register' parameter values: 'owner', 'node'";
logger.debug(supportedTypesMsg);
return new ResponseEntity<>(supportedTypesMsg, HttpStatus.BAD_REQUEST);
}
} catch (WonProtocolException e) {
logger.info("Could not register " + registeredType, e);
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
use of won.protocol.exception.WonProtocolException in project webofneeds by researchstudio-sat.
the class RegistrationServerCertificateBased method registerOwner.
@Transactional
public String registerOwner(Object certificateChainObj) throws WonProtocolException {
String alias = null;
X509Certificate[] ownerCertChain = new X509Certificate[] { (X509Certificate) certificateChainObj };
checkTrusted(ownerCertChain);
try {
alias = aliasGenerator.generateAlias(ownerCertChain[0]);
logger.info("Public key hash to be used as ownerApplicationId: {}", alias);
alias = ownerManagementService.registerOwnerApplication(alias);
} catch (Exception e) {
logger.warn("could not register owner", e);
throw new WonProtocolException(e);
}
return alias;
}
Aggregations