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;
}
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;
}
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());
}
}
}
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;
}
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;
}
Aggregations