Java Code Examples for org.gluu.oxauth.client.AuthorizationRequest#setAcrValues()
The following examples show how to use
org.gluu.oxauth.client.AuthorizationRequest#setAcrValues() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AuthorizationAction.java From oxAuth with MIT License | 5 votes |
public String getOpenIdRequestObject() { openIdRequestObject = ""; try { if (useOpenIdRequestObject) { AuthorizationRequest req = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); req.setState(state); req.setRequestUri(requestUri); req.setMaxAge(maxAge); req.setUiLocales(StringUtils.spaceSeparatedToList(uiLocales)); req.setClaimsLocales(StringUtils.spaceSeparatedToList(claimsLocales)); req.setIdTokenHint(idTokenHint); req.setLoginHint(loginHint); req.setAcrValues(StringUtils.spaceSeparatedToList(acrValues)); req.setRegistration(registration); req.setDisplay(display); req.getPrompts().addAll(prompt); OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(); JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest( req, SignatureAlgorithm.NONE, (String) null, cryptoProvider); jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NAME, ClaimValue.createNull())); jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.NICKNAME, ClaimValue.createEssential(false))); jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL, ClaimValue.createNull())); jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.EMAIL_VERIFIED, ClaimValue.createNull())); jwtAuthorizationRequest.addUserInfoClaim(new Claim(JwtClaimName.PICTURE, ClaimValue.createEssential(false))); jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_TIME, ClaimValue.createNull())); jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.AUTHENTICATION_CONTEXT_CLASS_REFERENCE, ClaimValue.createValueList(new String[]{"basic"}))); jwtAuthorizationRequest.getIdTokenMember().setMaxAge(86400); openIdRequestObject = jwtAuthorizationRequest.getDecodedJwt(); } } catch (Exception e) { log.error(e.getMessage(), e); } return openIdRequestObject; }
Example 2
Source File: GetAuthorizationCodeOperation.java From oxd with Apache License 2.0 | 5 votes |
@Override public IOpResponse execute(GetAuthorizationCodeParams params) { final Rp rp = getRp(); String nonce = Strings.isNullOrEmpty(params.getNonce()) ? UUID.randomUUID().toString() : params.getNonce(); String state = Strings.isNullOrEmpty(params.getState()) ? UUID.randomUUID().toString() : params.getState(); final AuthorizationRequest request = new AuthorizationRequest(responseTypes(rp.getResponseTypes()), rp.getClientId(), rp.getScope(), rp.getRedirectUri(), nonce); request.setState(state); request.setAuthUsername(params.getUsername()); request.setAuthPassword(params.getPassword()); request.getPrompts().add(Prompt.NONE); request.setAcrValues(acrValues(params, rp)); getStateService().putNonce(nonce); getStateService().putState(state); final AuthorizeClient authorizeClient = getOpClientFactory().createAuthorizeClient(getDiscoveryService().getConnectDiscoveryResponse(rp).getAuthorizationEndpoint()); authorizeClient.setRequest(request); authorizeClient.setExecutor(getHttpService().getClientExecutor()); final AuthorizationResponse response = authorizeClient.exec(); if (response != null) { getStateService().putState(params.getState()); return new GetAuthorizationCodeResponse(response.getCode()); } else { LOG.error("Failed to get response from oxauth client."); } return null; }
Example 3
Source File: AuthenticationFilter.java From oxTrust with MIT License | 4 votes |
public String getOAuthRedirectUrl(final HttpServletRequest request, final HttpServletResponse response) throws Exception { String authorizeUrl = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_AUTHORIZE_URL, null); String clientScopes = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_SCOPE, null); String clientId = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_ID, null); String clientSecret = getPropertyFromInitParams(null, Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, null); if (clientSecret != null) { try { clientSecret = StringEncrypter.defaultInstance().decrypt(clientSecret, Configuration.instance().getCryptoPropertyValue()); } catch (EncryptionException ex) { log.error("Failed to decrypt property: " + Configuration.OAUTH_PROPERTY_CLIENT_PASSWORD, ex); } } String redirectUri = constructRedirectUrl(request); List<String> scopes = Arrays.asList(clientScopes.split(StringUtils.SPACE)); List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE); String nonce = UUID.randomUUID().toString(); String rfp = UUID.randomUUID().toString(); String jti = UUID.randomUUID().toString(); // Lookup for relying party ID final String key = request.getParameter(ExternalAuthentication.CONVERSATION_KEY); request.getSession().setAttribute(SESSION_CONVERSATION_KEY, key); ProfileRequestContext prc = ExternalAuthentication.getProfileRequestContext(key, request); String relyingPartyId = ""; final RelyingPartyContext relyingPartyCtx = prc.getSubcontext(RelyingPartyContext.class); if (relyingPartyCtx != null) { relyingPartyId = relyingPartyCtx.getRelyingPartyId(); log.info("relyingPartyId found: " + relyingPartyId); } else log.warn("No RelyingPartyContext was available"); // JWT OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(); JwtState jwtState = new JwtState(SignatureAlgorithm.HS256, clientSecret, cryptoProvider); jwtState.setRfp(rfp); jwtState.setJti(jti); if (relyingPartyId != null && !"".equals(relyingPartyId)) { String additionalClaims = String.format("{relyingPartyId: '%s'}", relyingPartyId); jwtState.setAdditionalClaims(new JSONObject(additionalClaims)); } else log.warn("No relyingPartyId was available"); String encodedState = jwtState.getEncodedJwt(); AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(encodedState); Cookie currentShibstateCookie = getCurrentShibstateCookie(request); if (currentShibstateCookie != null) { String requestUri = decodeCookieValue(currentShibstateCookie.getValue()); log.debug("requestUri = \"" + requestUri + "\""); String authenticationMode = determineAuthenticationMode(requestUri); if (StringHelper.isNotEmpty(authenticationMode)) { log.debug("acr_values = \"" + authenticationMode + "\""); authorizationRequest.setAcrValues(Arrays.asList(authenticationMode)); updateShibstateCookie(response, currentShibstateCookie, requestUri, "/" + Configuration.OXAUTH_ACR_VALUES + "/" + authenticationMode); } } // Store for validation in session final HttpSession session = request.getSession(false); session.setAttribute(Configuration.SESSION_AUTH_STATE, encodedState); session.setAttribute(Configuration.SESSION_AUTH_NONCE, nonce); return authorizeUrl + "?" + authorizationRequest.getQueryString(); }