List of usage examples for org.springframework.security.oauth2.common OAuth2AccessToken ACCESS_TOKEN
String ACCESS_TOKEN
To view the source code for org.springframework.security.oauth2.common OAuth2AccessToken ACCESS_TOKEN.
Click Source Link
From source file:eu.trentorise.smartcampus.resourceprovider.filter.ResourceAssistant.java
public boolean checkPermission(Oauth2ExtRequest forwardRequest) { WebClient client = WebClient.create(permissionHostUrl); Boolean resp = client.path("/resources/access").accept(MediaType.APPLICATION_JSON) .header(OAuth2AccessToken.ACCESS_TOKEN, forwardRequest.getOauthTokenOfService()) .post(forwardRequest, Boolean.class); // return resp; return resp;/*from w w w. j a v a 2 s . co m*/ }
From source file:com.acc.conv.Oauth2AccessTokenConverter.java
@Override public void marshal(final Object source, final HierarchicalStreamWriter writerOrig, final MarshallingContext context) { final OAuth2AccessToken token = (OAuth2AccessToken) source; final ExtendedHierarchicalStreamWriter writer = (ExtendedHierarchicalStreamWriter) writerOrig .underlyingWriter();/*from ww w . j a va 2s. c om*/ writer.startNode(OAuth2AccessToken.ACCESS_TOKEN, String.class); writer.setValue(formattedValue(token.getValue())); writer.endNode(); writer.startNode(OAuth2AccessToken.TOKEN_TYPE, String.class); writer.setValue(formattedValue(token.getTokenType())); writer.endNode(); final OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { writer.startNode(OAuth2AccessToken.REFRESH_TOKEN, String.class); writer.setValue(formattedValue(refreshToken.getValue())); writer.endNode(); } final Date expiration = token.getExpiration(); if (expiration != null) { final long now = System.currentTimeMillis(); writer.startNode(OAuth2AccessToken.EXPIRES_IN, Integer.class); writer.setValue(String.valueOf((expiration.getTime() - now) / 1000)); writer.endNode(); } final Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { final StringBuffer scopes = new StringBuffer(); for (final String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope); scopes.append(s); scopes.append(' '); } writer.startNode(OAuth2AccessToken.SCOPE, String.class); writer.setValue(formattedValue(scopes.substring(0, scopes.length() - 1))); writer.endNode(); } final Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (final String key : additionalInformation.keySet()) { writer.startNode(key, String.class); writer.setValue(formattedValue(String.valueOf(additionalInformation.get(key)))); writer.endNode(); } }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java
@Override public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject();/* www . j av a2s . co m*/ jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); } Date expiration = token.getExpiration(); if (expiration != null) { long now = System.currentTimeMillis(); jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); } Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { StringBuffer scopes = new StringBuffer(); for (String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + ""); scopes.append(s); scopes.append(" "); } jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); } Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (String key : additionalInformation.keySet()) { jgen.writeObjectField(key, additionalInformation.get(key)); } jgen.writeEndObject(); }
From source file:org.joyrest.oauth2.interceptor.AuthenticationInterceptor.java
private Optional<Authentication> extractToken(InternalRequest<Object> req) { return extractHeaderToken(req).filter(Objects::isNull) .flatMap(value -> req.getQueryParam(OAuth2AccessToken.ACCESS_TOKEN)).filter(Objects::nonNull) .map(token -> new PreAuthenticatedAuthenticationToken(token, "")); }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Deserializer.java
@Override public OAuth2AccessToken deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String tokenValue = null;//from w ww. j a v a2s . co m String tokenType = null; String refreshToken = null; Long expiresIn = null; Set<String> scope = null; Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>(); // TODO What should occur if a parameter exists twice while (jp.nextToken() != JsonToken.END_OBJECT) { String name = jp.getCurrentName(); jp.nextToken(); if (OAuth2AccessToken.ACCESS_TOKEN.equals(name)) { tokenValue = jp.getText(); } else if (OAuth2AccessToken.TOKEN_TYPE.equals(name)) { tokenType = jp.getText(); } else if (OAuth2AccessToken.REFRESH_TOKEN.equals(name)) { refreshToken = jp.getText(); } else if (OAuth2AccessToken.EXPIRES_IN.equals(name)) { try { expiresIn = jp.getLongValue(); } catch (JsonParseException e) { expiresIn = Long.valueOf(jp.getText()); } } else if (OAuth2AccessToken.SCOPE.equals(name)) { String text = jp.getText(); scope = OAuth2Utils.parseParameterList(text); } else { additionalInformation.put(name, jp.readValueAs(Object.class)); } } // TODO What should occur if a required parameter (tokenValue or tokenType) is missing? DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(tokenValue); accessToken.setTokenType(tokenType); if (expiresIn != null) { accessToken.setExpiration(new Date(System.currentTimeMillis() + (expiresIn * 1000))); } if (refreshToken != null) { accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken)); } accessToken.setScope(scope); accessToken.setAdditionalInformation(additionalInformation); return accessToken; }
From source file:org.springframework.security.oauth2.provider.authentication.BearerTokenExtractor.java
protected String extractToken(HttpServletRequest request) { // first check the header... String token = extractHeaderToken(request); // bearer type allows a request parameter as well if (token == null) { logger.debug("Token not found in headers. Trying request parameters."); token = request.getParameter(OAuth2AccessToken.ACCESS_TOKEN); if (token == null) { logger.debug("Token not found in request parameters. Not an OAuth2 request."); }/*from w ww. jav a2 s . c om*/ } return token; }
From source file:org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter.java
protected String parseToken(HttpServletRequest request) { // first check the header... String token = parseHeaderToken(request); // bearer type allows a request parameter as well if (token == null) { logger.debug("Token not found in headers. Trying request parameters."); token = request.getParameter(OAuth2AccessToken.ACCESS_TOKEN); if (token == null) { logger.debug("Token not found in request parameters. Not an OAuth2 request."); }/*from ww w . j av a 2 s.c o m*/ } return token; }