use of org.apache.cxf.rs.security.oauth.provider.MD5SequenceGenerator in project cxf by apache.
the class ApplicationController method registerApp.
@RequestMapping("/registerClient")
public ModelAndView registerApp(@ModelAttribute("client") ClientApp clientApp) throws Exception {
if (StringUtils.isEmpty(clientApp.getClientName())) {
clientApp.setError("Client name field is required!");
return handleInternalRedirect(clientApp);
}
MD5SequenceGenerator tokenGen = new MD5SequenceGenerator();
Principal principal = SecurityContextHolder.getContext().getAuthentication();
String consumerKey = clientApp.getConsumerKey();
if (StringUtils.isEmpty(consumerKey)) {
consumerKey = tokenGen.generate((principal.getName() + clientApp.getClientName()).getBytes(StandardCharsets.UTF_8));
}
String secretKey = tokenGen.generate(new SecureRandom().generateSeed(20));
Client clientInfo = new Client(consumerKey, secretKey, clientApp.getClientName(), null);
clientInfo.setCallbackURI(clientApp.getCallbackURL());
clientInfo.setLoginName(principal.getName());
Client authNInfo = clientManager.registerNewClient(consumerKey, clientInfo);
if (authNInfo != null) {
clientApp.setError("Client already exists!");
return handleInternalRedirect(clientApp);
}
ModelAndView modelAndView = new ModelAndView("clientDetails");
modelAndView.getModel().put("clientInfo", clientInfo);
return modelAndView;
}
Aggregations