/** * Returns the name of this principal. * * @return the name of this principal. */ public String getName() { return getIdentifier(); }
public String getName() { return getIdentifier(); }; };
/** * Returns the user identifier. * * @param request * The request to inspect. * @param response * The response to inspect. * @return The user identifier. */ protected String getIdentifier(Request request, Response response) { return request.getChallengeResponse().getIdentifier(); }
@Override public void formatCredentials( StringBuilder sb, ChallengeResponse challenge, Request request, Series<Parameter> httpHeaders ) { try { final String credentials = challenge.getIdentifier() + ':' + new String( challenge.getSecret() ); sb.append( Base64.encode( credentials.getBytes( "US-ASCII" ), false ) ); } catch ( final UnsupportedEncodingException e ) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials" ); } }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { final CharArrayWriter credentials = new CharArrayWriter(); credentials.write("^@"); credentials.write(challenge.getIdentifier()); credentials.write("^@"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "US-ASCII", false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
@Override public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { try { if (challenge == null) { throw new RuntimeException( "No challenge provided, unable to encode credentials"); } else { CharArrayWriter credentials = new CharArrayWriter(); credentials.write(challenge.getIdentifier()); credentials.write(":"); credentials.write(challenge.getSecret()); cw.append(Base64.encode(credentials.toCharArray(), "ISO-8859-1", false)); } } catch (UnsupportedEncodingException e) { throw new RuntimeException( "Unsupported encoding, unable to encode credentials"); } catch (IOException e) { throw new RuntimeException( "Unexpected exception, unable to encode credentials", e); } }
final String identifier = challenge.getIdentifier(); sb.append('/'); sb.append(identifier);
/** {@inheritDoc} */ @Override public int hashCode() { // Note that the secret is simply discarded from hash code calculation // because we don't want it to be materialized as a string return SystemUtils .hashCode(getScheme(), getIdentifier(), getRawValue()); }
/** {@inheritDoc} */ @Override public int hashCode() { return Engine.hashCode(getScheme(), getIdentifier(), (getSecret() == null) ? null : new String(getSecret()), getCredentials()); }
public void formatResponse(ChallengeWriter cw, ChallengeResponse challenge, Request request, Series<Header> httpHeaders) { cw.append("id=\""); cw.append(challenge.getIdentifier()); cw.append("\",ts=\""); cw.append((new Date()).getTime()); cw.append("\",nonce=\""); String nonce = CryptoUtils.makeNonce(String.valueOf(challenge .getSecret())); cw.append(nonce); cw.append("\",mac=\""); cw.append(String.valueOf(challenge.getSecret())); cw.append("\""); } }
|| !Objects.equals(getIdentifier(), that.getIdentifier()) || !Objects.equals(getScheme(), that.getScheme())) { return false;
if (getIdentifier() != null) { result = getIdentifier().equals(that.getIdentifier()); } else { result = (that.getIdentifier() == null);
/** * Invoked upon failed authentication. By default, it updates the request's * clientInfo and challengeResponse "authenticated" properties, and returns * {@link Filter#STOP}. * * @param request * The request sent. * @param response * The response to update. * @return The filter continuation code. */ protected int unauthenticated(Request request, Response response) { boolean loggable = request.isLoggable() && getLogger().isLoggable(Level.FINE); if (request.getChallengeResponse() != null && loggable) { getLogger().log( Level.FINE, "The authentication failed for the identifer \"" + request.getChallengeResponse().getIdentifier() + "\" using the " + request.getChallengeResponse().getScheme() + " scheme."); } // Update the client info accordingly if (request.getClientInfo() != null) { request.getClientInfo().setAuthenticated(false); } // Stop the filtering chain return STOP; }
@SubResource public void administration() { ChallengeResponse challenge = Request.getCurrent().getChallengeResponse(); if( challenge == null ) { Response.getCurrent() .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) ); throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() ); if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) ) { throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } current().select( user ); subResource( AdministrationResource.class ); }
.getChallengeResponse().getIdentifier(), request.getChallengeResponse().getScheme());
Level.FINE, "The authentication succeeded for the identifer \"" + request.getChallengeResponse().getIdentifier() + "\" using the " + request.getChallengeResponse().getScheme()
&& ChallengeScheme.FTP_PLAIN.equals(request .getChallengeResponse().getScheme()) && (request.getChallengeResponse().getIdentifier() != null)) { userInfo = request.getChallengeResponse() .getIdentifier();
@Override protected void afterHandle(Request request, Response response) { super.afterHandle(request, response); Cookie cookie = request.getCookies().getFirst("Credentials"); if (request.getClientInfo().isAuthenticated() && (cookie == null)) { String identifier = request.getChallengeResponse().getIdentifier(); String secret = new String(request.getChallengeResponse() .getSecret()); CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret); cookieSetting.setAccessRestricted(true); cookieSetting.setPath("/"); cookieSetting.setComment("Unsecured cookie based authentication"); cookieSetting.setMaxAge(30); response.getCookieSettings().add(cookieSetting); } }
@Override protected void afterHandle(Request request, Response response) { super.afterHandle(request, response); Cookie cookie = request.getCookies().getFirst("Credentials"); if (request.getClientInfo().isAuthenticated() && (cookie == null)) { String identifier = request.getChallengeResponse().getIdentifier(); String secret = new String(request.getChallengeResponse() .getSecret()); CookieSetting cookieSetting = new CookieSetting("Credentials", identifier + "=" + secret); cookieSetting.setAccessRestricted(true); cookieSetting.setPath("/"); cookieSetting.setComment("Unsecured cookie based authentication"); cookieSetting.setMaxAge(30); response.getCookieSettings().add(cookieSetting); } }
clientId = cr.getIdentifier(); clientSecret = cr.getSecret();