/** * Returns the OpenId Connect client id. * * @return client id */ public String getClientId() { return identityProvider.getClientId().getValue(); }
public static Cookie getCookieToken(HttpServletRequest request, ClientID clientId) { Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; } for (Cookie cookie : cookies) { if (cookie.getName().equals("REMEMBER_" + clientId.getValue()) && StringUtils.isNotEmpty(cookie.getValue())) { return cookie; } } return null; }
public static void setLoginSessionCookie(HttpServletRequest request, HttpServletResponse response, String encryptedToken, ClientID clientID) { Cookie cookie = new Cookie("REMEMBER_" + clientID.getValue(), encryptedToken); cookie.setMaxAge(EXPIRATION); cookie.setSecure(request.isSecure()); response.addCookie(cookie); }
public static void removeCookieToken(HttpServletRequest request, HttpServletResponse response, ClientID clientID) { Cookie[] cookies = request.getCookies(); if (cookies == null) { return; } for (Cookie cookie : cookies) { if (cookie.getName().equals("REMEMBER_" + clientID.getValue())) { Cookie delete = new Cookie("REMEMBER_" + clientID.getValue(), ""); delete.setMaxAge(-1); response.addCookie(delete); return; } } }
Map<String, String> toParameters() { Map<String, String> params = new HashMap<String, String>(); params.put("client_id", getClientID().getValue()); return params; }
/** * Returns the OpenId Connect client id. * * @return client id */ public String getClientId() { return identityProvider.getClientId().getValue(); }
Map<String, String> toParameters() { Map<String, String> params = new HashMap<String, String>(); params.put("client_id", getClientID().getValue()); return params; }
Map<String, String> toParameters() { Map<String, String> params = new HashMap<String, String>(); params.put("client_id", getClientID().getValue()); return params; }
@Override public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof NameCallback) { ((NameCallback) callback).setName(plainClientSecret.getClientID().getValue()); continue; } if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(plainClientSecret.getClientSecret().getValue().toCharArray()); } } } };
@Override public void remove(String id, ClientID clientId) { Document query = new Document("_id", id); Document refreshQuery = new Document("refreshTokenRef", id); if (clientId != null) { query.append("clientId", clientId.getValue()); refreshQuery.append("clientId", clientId.getValue()); } DeleteResult result = collection.deleteOne(query); LOG.debug("delete {} : {} tokens", id, result.getDeletedCount()); result = collection.deleteMany(refreshQuery); LOG.debug("delete {} : {} access tokens", id, result.getDeletedCount()); }
public AuthCodeEntity(AuthorizationCode code, UserInfo userInfo, ClientID clientId, LoginSessionToken sessionId, URI redirectUri) { this.id = code.getValue(); if (userInfo != null) { this.userInfo = userInfo.toJSONObject().toJSONString(); } this.clientId = clientId.getValue(); this.loginSession = sessionId != null ? sessionId.getValue() : null; this.redirectUri = redirectUri != null ? redirectUri.toString() : null; }
@Override public void addAuthCode(AuthorizationCode code, UserInfo userInfo, ClientID clientId, LoginSessionToken sessionId, URI redirectUri) { Document document = new Document("_id", code.getValue()) .append("created", new Date()) .append("expires", new Date(System.currentTimeMillis() + 60000)) .append("userInfo", userInfo.toJSONObject()) .append("clientId", clientId.getValue()) .append("loginSession", sessionId == null ? null : sessionId.getValue()) .append("redirectUri", redirectUri.toString()); authCodeCollection.insertOne(document); }
public TokenEntity(Token token, UserInfo userInfo, ClientID clientId, LoginSessionToken sessionId, int refreshTokenLifeTime) { this.id = token.getValue(); this.token = token.toJSONObject().toJSONString(); if (token instanceof AccessToken && 0 != ((AccessToken) token).getLifetime()) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.SECOND, (int) ((AccessToken) token).getLifetime()); expires = cal.getTime(); } if (token instanceof RefreshToken) { if (refreshTokenLifeTime != 0) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.MILLISECOND, refreshTokenLifeTime); expires = cal.getTime(); } } if (userInfo != null) { this.userInfo = userInfo.toJSONObject().toJSONString(); } if (clientId != null) { this.clientId = clientId.getValue(); } if (sessionId != null) { this.loginSession = sessionId.getValue(); } }
private void generateAuthCode(AuthResponseContext context, AuthorizationRequest request) { log.debug("Calling generateAuthCode"); try { String code = new AuthorizationCode().getValue(); String scope = getScope(request); oauthDAO.addAuthCodeInfo(code, request.getClientID().getValue(), scope, request.getRedirectionURI()); context.setAuthCode(code); } catch (OAuthDAOException e) { String clientId = request.getClientID().getValue(); log.error("Error while saving auth code information for client Id: " + clientId, e); ErrorObject error = new ErrorObject(OAuth2Error.SERVER_ERROR.getCode()); context.setErrorObject(error); } }
Optional<Optional<String>> result = oauthDAO.getRedirectUri(request.getClientID().getValue()); if (result.isPresent()) { Optional<String> uri = result.get(); log.info("Client Id: " + request.getClientID().getValue() + ", does not exist "); ErrorObject error = new ErrorObject(OAuth2Error.UNAUTHORIZED_CLIENT.getCode()); context.setErrorObject(error); haltExecution.setTrue(); } catch (OAuthDAOException e) { String clientId = request.getClientID().getValue(); log.error("Error while getting public client information for client Id: " + clientId, e); ErrorObject error = new ErrorObject(OAuth2Error.SERVER_ERROR.getCode());
public Document asDocument() { Document document = new Document("_id", token.getValue()) .append("created", created) .append("clientId", clientId.getValue()) .append("userInfo", userInfo) .append("type", type.name()); if (sessionId != null) { document.append("sessionId", sessionId.getValue()); } if (expires != null) { document.append("expires", expires); } if (refreshTokenRef != null) { document.append("refreshTokenRef", refreshTokenRef); } return document; }
private AuthResponseContext processAuthRequest(AuthorizationRequest request) { log.debug("Calling processAuthRequest"); AuthResponseContext context = new AuthResponseContext(); context.setState(request.getState()); MutableBoolean haltExecution = new MutableBoolean(false); updateRedirectUriIfNotSent(context, request, haltExecution); if (haltExecution.isTrue()) { return context; } if (request.getResponseType().equals(new ResponseType(ResponseType.Value.CODE))) { // Auth Code grant generateAuthCode(context, request); } else if (request.getResponseType().equals(new ResponseType(ResponseType.Value.TOKEN))) { // Implicit grant generateAccessToken(context, request); } else { String responseType = request.getResponseType().toString(); String clientId = request.getClientID().getValue(); log.info("Value of response_type: " + responseType + " is invalid(client Id: " + clientId); ErrorObject error = new ErrorObject(OAuth2Error.INVALID_REQUEST.getCode()); context.setErrorObject(error); } return context; }