Search in sources :

Example 1 with Client

use of org.apache.cxf.rs.security.oauth.data.Client in project cxf by apache.

the class ApplicationController method listAuthorizedClients.

@RequestMapping("/listAuthorizedClients")
public ModelAndView listAuthorizedClients() {
    Set<Client> apps = clientManager.listAuthorizedClients();
    ModelAndView modelAndView = new ModelAndView("authorizedClientsList");
    modelAndView.getModelMap().put("clients", apps);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Client(org.apache.cxf.rs.security.oauth.data.Client) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Client

use of org.apache.cxf.rs.security.oauth.data.Client in project cxf by apache.

the class ApplicationController method listRegisteredClients.

@RequestMapping("/listRegisteredClients")
public ModelAndView listRegisteredClients() {
    Set<Client> apps = clientManager.listRegisteredClients();
    ModelAndView modelAndView = new ModelAndView("registeredClientsList");
    modelAndView.getModelMap().put("clients", apps);
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Client(org.apache.cxf.rs.security.oauth.data.Client) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Client

use of org.apache.cxf.rs.security.oauth.data.Client in project cxf by apache.

the class SampleOAuthDataProvider method removeRegisteredClient.

public synchronized void removeRegisteredClient(String consumerKey) {
    List<String> registeredApps = this.userRegisteredClients.get(consumerKey);
    this.clientAuthInfo.remove(consumerKey);
    // remove registered app
    registeredApps.remove(consumerKey);
    this.userRegisteredClients.put(consumerKey, registeredApps);
    // remove all authorized apps from other clients
    for (Map.Entry<String, List<String>> userAuthorizedClientsSet : userAuthorizedClients.entrySet()) {
        String principalName = userAuthorizedClientsSet.getKey();
        List<String> clients = userAuthorizedClientsSet.getValue();
        clients.remove(consumerKey);
        userAuthorizedClients.put(principalName, clients);
    }
    // remove access tokens
    for (Token token : oauthTokens.values()) {
        Client authNInfo = token.getClient();
        if (consumerKey.equals(authNInfo.getConsumerKey())) {
            oauthTokens.remove(token.getTokenKey());
        }
    }
}
Also used : List(java.util.List) Token(org.apache.cxf.rs.security.oauth.data.Token) Client(org.apache.cxf.rs.security.oauth.data.Client) Map(java.util.Map)

Example 4 with Client

use of org.apache.cxf.rs.security.oauth.data.Client in project cxf by apache.

the class MemoryOAuthDataProvider method createAccessToken.

public AccessToken createAccessToken(AccessTokenRegistration reg) throws OAuthServiceException {
    RequestToken requestToken = reg.getRequestToken();
    Client client = requestToken.getClient();
    requestToken = getRequestToken(requestToken.getTokenKey());
    String accessTokenString = generateToken();
    String tokenSecretString = generateToken();
    AccessToken accessToken = new AccessToken(client, accessTokenString, tokenSecretString, 3600, System.currentTimeMillis() / 1000);
    accessToken.setScopes(requestToken.getScopes());
    synchronized (oauthTokens) {
        oauthTokens.remove(requestToken.getTokenKey());
        oauthTokens.put(accessTokenString, accessToken);
        synchronized (userAuthorizedClients) {
            userAuthorizedClients.add(client.getConsumerKey(), client.getConsumerKey());
        }
    }
    return accessToken;
}
Also used : RequestToken(org.apache.cxf.rs.security.oauth.data.RequestToken) AccessToken(org.apache.cxf.rs.security.oauth.data.AccessToken) Client(org.apache.cxf.rs.security.oauth.data.Client)

Example 5 with Client

use of org.apache.cxf.rs.security.oauth.data.Client 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

Client (org.apache.cxf.rs.security.oauth.data.Client)8 AccessToken (org.apache.cxf.rs.security.oauth.data.AccessToken)3 RequestToken (org.apache.cxf.rs.security.oauth.data.RequestToken)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 OAuthMessage (net.oauth.OAuthMessage)2 OAuthProblemException (net.oauth.OAuthProblemException)2 Principal (java.security.Principal)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)1 OAuthPermission (org.apache.cxf.rs.security.oauth.data.OAuthPermission)1 RequestTokenRegistration (org.apache.cxf.rs.security.oauth.data.RequestTokenRegistration)1 Token (org.apache.cxf.rs.security.oauth.data.Token)1 MD5SequenceGenerator (org.apache.cxf.rs.security.oauth.provider.MD5SequenceGenerator)1 OAuthServiceException (org.apache.cxf.rs.security.oauth.provider.OAuthServiceException)1