Search in sources :

Example 1 with MD5SequenceGenerator

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;
}
Also used : MD5SequenceGenerator(org.apache.cxf.rs.security.oauth.provider.MD5SequenceGenerator) ModelAndView(org.springframework.web.servlet.ModelAndView) SecureRandom(java.security.SecureRandom) Client(org.apache.cxf.rs.security.oauth.data.Client) Principal(java.security.Principal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Principal (java.security.Principal)1 SecureRandom (java.security.SecureRandom)1 Client (org.apache.cxf.rs.security.oauth.data.Client)1 MD5SequenceGenerator (org.apache.cxf.rs.security.oauth.provider.MD5SequenceGenerator)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1